一些java基础

时间:2011-09-17 10:44:55

标签: java

更新::

1)。问题::

我写了 System.out.println("welcom");&         System.out.println("india");
我想要:: welcome india

但请注意::

欢迎
india

8 个答案:

答案 0 :(得分:8)

<强> 1

println始终打印换行符。要获得所需内容,请尝试:

System.out.print("welcome ");
System.out.print("india\n");

<强> 2

x++ 后增量++x是预增量。

所以:

int x = 5;
int y = ++x;

y将为6

但在:

int x = 5;
int y = x++;

y将为5

答案 1 :(得分:5)

1:System.out.print与System.out.println有什么区别?

2:++运算符做什么以及何时执行此操作?

答案 2 :(得分:1)

println

代表“打印行”,因此,如果您使用println,则会有“回车”,下一个println会打印一个新行(依此类推......)

x++++x不同:第二个增量变量的值然后继续,第一个继续使用语句,然后增量变量的值。

答案 3 :(得分:1)

的System.out.println( “开山鼻祖”); &安培;的System.out.println( “印度”);  你现在写的如果你想要同一行

  System.out.print("welcom "); 
  System.out.print("india");

x++ is Post-increment
Post-increment : add 1 to the value.
The value is returned before the increment is made, e.g.
   x = 1;
   y = x++;
Then y will hold 1 and x will hold 2

 ++x is pre increment
 Pre-increment : add 1 to the value.
The value is returned after the increment is made, e.g.
   x = 1;
   y = ++x;
 Then y will hold 2 and x will hold 2.

答案 4 :(得分:0)

尝试System.out.print&amp; 1发生在条件/表达发生之前;另一个;

答案 5 :(得分:0)

1)要打印字符串而不打印结束,请使用System.out.print()
2)
x++ - 增加x,并返回x的前一个值(增量前)
++x - 递增x,返回x的当前值(递增后)

这些是递增的Post和Pre修正版本。

答案 6 :(得分:0)

println()打印一行,并在下一行打印println语句(使用任何print语句)后打印的任何内容。

第二件事是++ x和x ++之间的区别。 ++ x在语句中执行任何其他操作时增加x BEFORE的值(预增量),并且x ++增加x的值,它在语句中执行任何其他操作(增量后)。

例如:

x = 1;
y = ++x; // value of y is 2, value of x is 2

x = 1;
y = x++; // value of y is 1 and x is 2

答案 7 :(得分:0)

System.out.println()已提供下一行,因为它完整的声明&amp; ++ x用于preincremet&amp; C ++是增量后的。