思考题:打印姓名对一个人的影响时,如何按照;姓名-年龄;的方式打印 java举例:System.out.println(z3)

Java and C# Comparison
Java and C# Comparison
This is a quick reference guide to highlight some key syntactical
differences between Java and C#. This is not a complete overview of either language. Hope you find this useful!
Also see .
public class HelloWorld {
&& public static void main(String[] args) {
&&&&& String name = "Java";
&&&&& if (args.length == 1)
&&&&&&&& name = args[0];
&&&&& System.out.println("Hello, " + name
namespace Hello {
&& public class HelloWorld {
&&&&& public static void Main(string[]
&&&&&&&& string name = "C#";
&& &&&&& if (args.Length == 1)
&& &&&&&&&& name = args[0];
&& &&&&& Console.WriteLine("Hello, " + name
short, int, long
float, double
arrays, classes, interfaces
int x = 123;
String y = Integer.toString(x);&
y = "456";&
x = Integer.parseInt(y);&&
double z = 3.5;
x = (int)&&
byte, sbyte
short, ushort, int, uint, long, ulong
float, double, decimal
structures, enumerations
arrays, classes, interfaces, delegates
int x = 123;
String y = x.ToString();&
y = "456";
x = int.Parse(y);&&
double z = 3.5;
x = (int)&&
final double PI = 3.14;
const double PI = 3.14;
readonly int MAX_HEIGHT = 9;
enum Action {Start, Stop, Rewind, Forward};
enum Status {
& Flunk(50), Pass(70), Excel(90);
& Status(int value) { this.value = }
& public int value() { }
Action a = Action.S
if (a != Action.Start)
& System.out.println(a);&&&&&&&&&&&&&&
Status s = Status.P
System.out.println(s.value());
enum Action {Start, Stop, Rewind, Forward};
enum Status {Flunk = 50, Pass = 70, Excel = 90};
Action a = Action.S
if (a != Action.Start)
& Console.WriteLine(a);&&&&&&
Status s = Status.P
Console.WriteLine((int) s);
==& && && &=& &=& !=
+& -& *& /
Math.Pow(x, y)
=& +=& -= &*=& /= & %= & &=& |=&
^=& &&=& &&=& &&&=& ++& --
& &| &^&&&~& &&& &&&
&&& ||&&&& | & ^ & !
Note: && and&||&perform short-circuit logical
evaluations
==& && && &=& &=& !=
+& -& *& /
Math.Pow(x, y)
=& +=& -= &*=& /= & %=& &=& |=&
^=& &&=& &&=& ++& --
& &| &^&&&~& &&& &&
&&& ||&&&& | & ^ & !
Note: && and&||&perform short-circuit logical
evaluations
greeting = age & 20 ? "What's up?" : "Hello";
if (x & y)
& System.out.println("greater");
if (x != 100) {&&&
int selection = 2;
switch (selection)&{&&&&
// Must be byte, short, int, char, or enum
x++;&&&&&&&&&&&
// Falls through to next case if no break
& case 2: y++;&&
& case 3: z++;&&
& default: other++;
greeting = age & 20 ? "What's up?" : "Hello";
if (x & y)&
& Console.WriteLine("greater");
if (x != 100) {&&&
string color = "red";
switch (color)&{&&&&&&&&&&&&&&&&&&&&&&&&&
// Can be any predefined type
& case "red":&&& r++;&&&
&&&&& // break is
no fall-through
& case "blue":&& b++;&&
& case "green": g++;&&
& default:&other++;&&& &
&&&&& // break necessary on default
while (i & 10)
for (i = 2; i &= 10; i += 2)&
& System.out.println(i);
while (i & 10);
for (int i : numArray)& &
import java.util.ArrayL
ArrayList&Object& list = new ArrayList&Object&();
list.add(10);&& &
list.add("Bisons");
list.add(2.3);&&&
for (Object o : list)&
System.out.println(o);
while (i & 10)
for (i = 2; i &= 10; i += 2)
& Console.WriteLine(i);
while (i & 10);
foreach (int i in numArray)&
// foreach can be used to iterate through any
collection&
using System.C
ArrayList list = new ArrayList();
list.Add(10);
list.Add("Bisons");
list.Add(2.3);
foreach (Object o in list)
& Console.WriteLine(o);
int nums[] =&{1, 2, 3};&&
or&& int[] nums = {1, 2, 3};
for (int i = 0; i & nums. i++)
& System.out.println(nums[i]);
String names[] = new String[5];
names[0] = "David";
float twoD[][] = new float[rows][cols];
twoD[2][0] = 4.5;
int[][] jagged = new int[5][];
jagged[0] = new int[5];
jagged[1] = new int[2];
jagged[2] = new int[3];
jagged[0][4] = 5;
int[] nums = {1, 2, 3};
for (int i = 0; i & nums.L i++)
& Console.WriteLine(nums[i]);
string[] names = new string[5];
names[0] = "David";
float[,] twoD = new float[rows, cols];
twoD[2,0] = 4.5f;
int[][] jagged = new int[3][] {
& & new int[5], new int[2], new int[3] };
jagged[0][4] = 5;
int Add(int x, int y) {
&& return x +
int sum = Add(2, 3);
void PrintSum(int x, int y) {
&& System.out.println(x + y);
PrintSum(2, 3);&
void TestFunc(int x, Point p) {
&& p.x++;&&&&&&
class Point {
&& public int x,
Point p = new Point();
int a = 1;
TestFunc(a, p);
System.out.println(a + " " + p.x + " " + (p == null) );&
int Sum(int ... nums) {
& int sum = 0;
& for (int i : nums)
& & sum +=
int total = Sum(4, 3, 2, 1);&&
int Add(int x, int y) {
&& return x +
int sum = Add(2, 3);
void PrintSum(int x, int y) {
&& Console.WriteLine(x + y);
PrintSum(2, 3);&
void TestFunc(int x, ref int y, out int z,
Point p1, ref Point p2) {
&& x++;& y++;& z = 5;
&& p1.x++;&&&&&&
&& p1 =& &
class Point {
&& public int x,
Point p1 = new Point();
Point p2 = new Point();
int a = 1, b = 1,&&
TestFunc(a, ref b, out c, p1, ref
Console.WriteLine("{0} {1} {2} {3} {4}",
&& a, b, c, p1.x, p2 == null); &
int Sum(params int[] nums) {
& int sum = 0;
& foreach (int i in nums)
&&& sum +=
int total = Sum(4, 3, 2, 1);&& //
returns 10
String school = "Harding ";
school = school + "University";&&
String&mascot = "Bisons";
if (mascot == "Bisons")&& &
if (mascot.equals("Bisons"))&&
if (mascot.equalsIgnoreCase("BISONS"))&&
if (mascot.compareTo("Bisons") == 0)&&
System.out.println(mascot.substring(2, 5));&&
java.util.Calendar c = new java.util.GregorianCalendar();
String s = String.format(&My birthday: %1$tb %1$te, %1$tY&,
StringBuffer buffer = new StringBuffer("two
buffer.append("three ");
buffer.insert(0, "one ");
buffer.replace(4, 7, "TWO");
System.out.println(buffer);&&&&
string school = "Harding ";
school = school + "University";&&
string&mascot = "Bisons";
if (mascot == "Bisons")& &
if (mascot.Equals("Bisons"))& &
if (mascot.ToUpper().Equals("BISONS"))&&
if (mascot.CompareTo("Bisons") == 0)&&&
Console.WriteLine(mascot.Substring(2, 3));&&&
DateTime dt = new DateTime();
string s = &My birthday: & + dt.ToString(&MMM dd, yyyy&);
System.Text.StringBuilder buffer = new System.Text.StringBuilder("two
buffer.Append("three ");
buffer.Insert(0, "one ");
buffer.Replace("two", "TWO");
Console.WriteLine(buffer);&&&&
Exception ex = new Exception("Something is really wrong.");
& x = 10 /
} catch (Exception ex) {
& System.out.println(ex.getMessage());&
} finally {
Exception up = new Exception("Something is really wrong.");
& x = 10 /
} catch (Exception ex) {&&&&&
& Console.WriteLine(ex.Message);
} finally {
package psci.
import psci.graphics.R
import psci.graphics.*; &
namespace psci.Graphics {
namespace Harding {
& namespace Compsci {
&&& namespace Graphics {
using Rectangle = pSci.Graphics.R
using psci.G
class FootballGame extends Competition {
interface IAlarmClock {
interface IAlarmClock extends IClock {
class WristWatch implements IAlarmClock,
protected internal
class FootballGame : Competition {
interface IAlarmClock {
interface IAlarmClock : IClock {
class WristWatch : IAlarmClock, ITimer {
class SuperHero {
& private int mPowerL
& public SuperHero() {
&&& mPowerLevel = 0;
& public SuperHero(int powerLevel) {
&&& this.mPowerLevel= powerL
& protected void finalize() throws Throwable {&
&&&&super.finalize();&&
class SuperHero {
& private int mPowerL
& public SuperHero() {
&&&&&mPowerLevel = 0;
& public SuperHero(int powerLevel) {
&&& this.mPowerLevel= powerL&
& ~SuperHero() {
SuperHero hero = new SuperHero();
hero.setName(&SpamMan&);
hero.setPowerLevel(3);
hero.Defend(&Laura Jones&);
SuperHero.Rest(); &
SuperHero hero2 = &&
hero2.setName(&WormWoman&);
System.out.println(hero.getName()); &
hero = null; &&
if (hero == null)
hero = new SuperHero();
Object obj = new SuperHero();
System.out.println(&object's type: & + obj.getClass().toString());
if (obj instanceof SuperHero)
& System.out.println(&Is a SuperHero object.&);
SuperHero hero = new SuperHero();
hero.Name = "SpamMan";
hero.PowerLevel = 3;
hero.Defend("Laura Jones");
SuperHero.Rest();&&
SuperHero hero2 =&&
hero2.Name = "WormWoman";
Console.WriteLine(hero.Name);&&
hero = null ;&&
if (hero == null)
& hero = new SuperHero();
Object obj = new SuperHero();&
Console.WriteLine(&object's type: & + obj.GetType().ToString());
if (obj is SuperHero)
& Console.WriteLine("Is a SuperHero object.");
private int mS
public int getSize() { return mS }
public void setSize(int value) {
& if (value & 0)
& & mSize = 0;
& & mSize =
int s = shoe.getSize();
shoe.setSize(s+1);
private int mS
public int Size {
& get { return mS }
& & if (value & 0)
& & & mSize = 0;
& & & mSize =
shoe.Size++;
No structs in Java.
struct StudentRecord {
& public StudentRecord(string name, float gpa) {
&&& this.name =
&&& this.gpa =
StudentRecord stu = new StudentRecord("Bob", 3.5f);
StudentRecord stu2 =&&
stu2.name = "Sue";
Console.WriteLine(stu.name);&&&
Console.WriteLine(stu2.name);&&
java.io.DataInput in = new
java.io.DataInputStream(System.in);
System.out.print("What is your name? ");
String name = in.readLine();
System.out.print("How old are you? ");
int age = Integer.parseInt(in.readLine());
System.out.println(name + " is " + age + " years old.");
int c = System.in.read();&&
System.out.println(c);&&&&&
System.out.printf(&The %s costs $%.2f for %d months.%n&, &studio&,
499.0, 3);
System.out.printf(&Today is %tD\n&, new java.util.Date());
Console.Write("What's your name? ");
string name = Console.ReadLine();
Console.Write("How old are you? ");
int age = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("{0} is {1} years old.", name, age);
Console.WriteLine(name + " is " + age + " years old.");
int c = Console.Read();&
Console.WriteLine(c);&&&
Console.WriteLine(&The {0} costs {1:C} for {2} months.\n&, &studio&,
499.0, 3);
Console.WriteLine(&Today is & + DateTime.Now.ToShortDateString());
import java.io.*;
FileWriter writer = new FileWriter(&c:\\myfile.txt&);
writer.write(&Out to file.\n&);
writer.close();
FileReader reader = new FileReader(&c:\\myfile.txt&);
BufferedReader br = new BufferedReader(reader);
String line = br.readLine();
while (line != null) {
& System.out.println(line);
& line = br.readLine();
reader.close();
FileOutputStream out = new FileOutputStream(&c:\\myfile.dat&);
out.write(&Text data&.getBytes());
out.write(123);
out.close();
FileInputStream in = new FileInputStream(&c:\\myfile.dat&);
byte buff[] = new byte[9];
in.read(buff, 0, 9); &&
String s = new String(buff);
int num = in.read();
in.close();
using System.IO;
StreamWriter writer = File.CreateText("c:\\myfile.txt");
writer.WriteLine("Out to file.");
writer.Close();
StreamReader reader = File.OpenText("c:\\myfile.txt");
string line = reader.ReadLine();
while (line != null) {
& Console.WriteLine(line);
& line = reader.ReadLine();
reader.Close();
BinaryWriter out = new BinaryWriter(File.OpenWrite("c:\\myfile.dat"));
out.Write(&Text data&);
out.Write(123);
out.Close();
BinaryReader in = new BinaryReader(File.OpenRead("c:\\myfile.dat"));
string s = in.ReadString();
int num = in.ReadInt32();
in.Close();
Page last modified:
This work is licensed under a .
Please send any corrections or comments to .线程 感觉怎么这么难呢
,System.out.printl【java吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:627,218贴子:
线程 感觉怎么这么难呢
,System.out.printl收藏
2楼放我的奇葩线程
public void run() {// TODO Auto-generated method stubwhile (true) {
System.out.println(&&);if (isRun) {// System.out.println(&线程还没有停止&);sum += (int) (Math.random() * 4);text.setText(xM + &-----&&&& + sum + &米&);}try {Thread.sleep((int) (Math.random() * 100));} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}
我设了2个按钮设置isRun的值,,我把第一个打印语句注释掉,然后把sleep放进if里面,然后set IsRun为true,结果if里面的语句不会执行。
如果把第一个打印语句放在if外面 或者把sleep放在if外面,再点击那个设置true的按钮就可以实现,通过按钮来控制线程if里面的语句是否执行了。还有个设置isRun为false的按钮
这究竟是怎么回事啊?我就不懂了 system.out.prointln怎么会和这个线程 能不能用按钮控制启动与否 有关系呢
你是说把try-catch block放到if block里边,sysout不能打印出“线程还没有停止”?
登录百度帐号推荐应用}

我要回帖

更多关于 知道姓名怎么查一个人 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信