開発環境
- OS: macOS High Sierra - Apple
- IDE(統合開発環境): Visual Studio for Mac
- プログラミング言語: C#
初めてのC# 第2版 (Jesse Liberty (著)、Brian MacDonald (著)、日向 俊二 (翻訳)、オライリージャパン)の7章(クラスとオブジェクト)、7.10(練習問題)、練習7-1を取り組んでみる。
コード
using System;
namespace Sample7_1
{
class Math
{
public float Add(float a, float b)
{
return a + b;
}
public float Subtract(float a, float b)
{
return a - b;
}
public float Multiply(float a, float b)
{
return a * b;
}
public float Divide(float a, float b)
{
return a / b;
}
}
class Program
{
static void Main(string[] args)
{
Math math = new Math();
Console.WriteLine(
"和: {0}、差: {1}、積: {2}、商: {3}",
math.Add(1, 2), math.Subtract(1, 2),
math.Multiply(1, 2), math.Divide(1, 2));
Console.WriteLine(
"和: {0}、差: {1}、積: {2}、商: {3}",
math.Add(2, 1), math.Subtract(2, 1),
math.Multiply(2, 1), math.Divide(2, 1));
}
}
}
入出力結果(Terminal)
和: 3、差: -1、積: 2、商: 0.5 和: 3、差: 1、積: 2、商: 2 Press any key to continue...
0 コメント:
コメントを投稿