c#补充print(多态性问题)【C#】
生活随笔
收集整理的這篇文章主要介紹了
c#补充print(多态性问题)【C#】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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);}?
總結
以上是生活随笔為你收集整理的c#补充print(多态性问题)【C#】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: UVA1225 Digit
- 下一篇: generator 1【矩阵快速幂】