public class Test { public static void main(String[] args) { //main int a = 10; int b = 20; int c = a + b; float f = (float)0.1; double d = 3.14159; System.out.println("a="+a); //printf("a=%d\n",a); System.out.println("b="+b); //printf("b=%d\n",b); System.out.println("c="+c); //printf("c=%d\n",c); System.out.println("a="+a + " b="+b + " c="+c); //printf("a=%d b=%d c=%d\n",a,b,c); System.out.println(a + "+" + b + "=" + c); //printf("%d+%d=%d",a,b,c); System.out.println("f="+f); //printf("f=%d\n",c); System.out.println("d="+d); //printf("d=%d\n",c); } }
运行结果:
public class Test { public static void main(String[] args) { int a = 1; if(a > 0){ System.out.println("a是正整数"); if(a == 1){ System.out.println("它是正整数,而且是1"); }else{ System.out.println("它是正整数,不是1"); } }else{ System.out.println("a是非正整数"); } System.out.println("========================="); switch(a){ case 1: System.out.println("这是1"); break; case 2: System.out.println("这是2"); break; case 3: System.out.println("这是3"); break; } } }
运行结果:
public class Test { public static void main(String[] args) { int i; int j=3; for(i=0; i<3; i++){ System.out.println("Hello Wrold from for"); } while(i>0){ System.out.println("Hello Wrold from while"); i--; } do{ System.out.println("Hello Wrold from do...while"); j--; }while(j>0); } }