1、Java 基础语法练习题集 一、请指出下列程序的错误并改正 1、 Public class 1Demo Public static void main(String a); int i; int j=2/少; i+; System.ou.println(i+j); 2、 Public class 中国 Public static void main(String args) double x=.89; int j=087;h=0x56h45; byte b=2345; float f=0.2536; 3、 Public class Demo Public static void main(St
2、ring args)/少 int i=34; int j=89; int sum; sum=i/j; System.out.println(sum); Sum=i-j; System.out.println(sum); 4、 Public class Demo Public static void main(String args/少 ) x+; int x=2; int x=89; int y=0 x+=x+y; x*=y; 二、请指出下列程序的输出结果 1、 Public class Demo Public static void main(String args) int x=5,b=3
3、,h; double a=2.7; h=x/b+x%b; System.out.println(“h=“+h); a=h*b+x/b*a; System.out.println(“a=“+a); h=3 a=11.7 2、 Public class Demo Public static void main(String args) int x,y,z; x=y=z=6; x=+y+z+; System.out.println(“x=“+x+“y=“+y+“z=“+z); x=y+-+z; System.out.println(“x=“+x+“y=“+y+“z=“+z); x=y-+-z; Sy
4、stem.out.println(“x=“+x+“y=“+y+“z=“+z); x=13y=7z=7 x=-1y=8z=8 x=15y=7z=7 3、 Public class Demo Public static void main(String args) boolean a,b; a=56|3*7=c) System.out.println(“van.“); else System.out.println(“tank.“); Option are:bike. car.van.bus. Best is: van. 6、 Public class Demo Public static voi
5、d main(String args) int x=0,sum=100; while(x20) sum-=x System.out.println(“x=“+x); if(x4) x+=4; else x+=2; System.out.println(“sum=“+sum); sum=100 7、 Public class Demo Public static void main(String args) int i=0 for(int x=0;x=j) break; j-; i+; 7 3、 Public class Demo Public static void main(String args) int j=21,i=0; while(ij) j-=2; i+=2; if(j-i=5) break; 4 4、 Public class Demo Public static void main(String args) int j=21,i=0; while(ij) if(j-i=5) break; j-=2; i+=2 5 5、 Public class Demo Public static void main(String args) int j=10,i=5; do i=(j-i)/2;