Java中用于C#格式化字符串cout的等效语句

时间:2012-12-26 23:13:34

标签: c# java

以下语句的Java等效指令是什么:

String name;
cout << "So your name is  " << name << endl;  

或者在C#中

console.writeline("So your name is {0} ", name);

1 个答案:

答案 0 :(得分:5)

String name;
cout<<"So your name is  "<<name<<endl; 

相当于:

String name = ...;
System.out.println("So your name is " + name);

Console.WriteLine("So your name is {0}", name);

相当于:

System.out.printf("So your name is %s", name);