c#補充print(多態性問題)
題目描述
根據給出代碼,補寫缺失代碼,當print函數內為整數的時候,輸出整數的三次方,為浮點數,輸出其二次方,為字符串時,直接輸出。
using System;
namespace PolymorphismApplication
{
? ?class Printdata
? ?{
? ? ? /******************************************/
? ? ? ? ?在此處補寫代碼,并只提交此處的代碼
? ?/******************************************/
? ? ? static void Main(string[] args)
? ? ? {
? ? ? ? ?Printdata p = new Printdata();
? ? ? ? ?
? ? ? ? ?p.print(2);
? ? ? ??
? ? ? ? ?p.print(1.23);
? ? ??
? ? ? ? ?p.print("Hello world");
? ? ? ? ?Console.ReadKey();
? ? ? }
? ?}
}
?
輸入
?
輸出
8
1.5129
Hello world
樣例輸出
8 1.5129 Hello world
public void print(int a){Console.WriteLine(a*a*a);}public void print(double a){Console.WriteLine(a*a);}public void print(String a){Console.WriteLine(a);}
?