以下选项中没有语法错误的是( ) 。
A: while (int i<7) { i++; System.out.println(“i is “+i); }
B: int j=3; while(j) { System.out.println(“ j is “+j); }
C: int j=0; for(int k=0; j + k !=10; j++,k++) { System.out.println(“ j is “+ j + “k is”+ k); }
D: int j=0; do{ System.out.println( “j is “+j++); if (j == 3) { continue loop; } }while (j<10);
A: while (int i<7) { i++; System.out.println(“i is “+i); }
B: int j=3; while(j) { System.out.println(“ j is “+j); }
C: int j=0; for(int k=0; j + k !=10; j++,k++) { System.out.println(“ j is “+ j + “k is”+ k); }
D: int j=0; do{ System.out.println( “j is “+j++); if (j == 3) { continue loop; } }while (j<10);
举一反三
- println 语句执行了多少次? for (int i = 0; i < 10;i++) for (int j = 0;j < i;j++) System .out.println(i * j)
- 中国大学MOOC: 写出程序的运行结果。#include <stdio.h>int main(){int c[10],i=0,j=0,k=0 ;int a[3]={5,9,10} ; int b[5]={12,24,26,37,48} ;while (i<3 && j<5)if (a[i]>b[j]) {c[k]=b[j] ; k++ ; j++ ;}else {c[k]=a[i] ; k++ ; i++ ;}while (i<3) {c[k]=a[i] ; i++ ; k++ ;}while (j<5) {c[k]=b[j] ; j++ ; k++ ;}for (i=0; i<k; i++) printf("%d ",c[i]); return 0;}
- 3、以下代码段执行后,输出结果是________。int i = 3; int j = 0; double k = 3.2; if(i < k) if(i == j) System.out.println(i); else System.out.println(j); else System.out.println(k);
- 以下程序的运行结果为( ) public class Ex6 { public static void main(String[] args) { int i,j,k; for(i=0;i<3;i++){ for(j=1;j<4;j++){ for(k=2;k<5;k++){ if((i==j)&&(j==k)) System.out.println(i); } } } } }
- 给出下列代码,哪行在编译时可能会有错误? ① public void modify(){ ② int i, j, k; ③ i = 100; ④ while ( i > 0 ){ ⑤ j = i * 2; ⑥ System.out.println (" The value of j is " + j ); ⑦ k = k + 1; ⑧ } ⑨ }