在while()do...while()for()switch()环境下,对break的使用。

xiaoxiao2021-02-28  28

答案:



代码:

public class bob {  public static void main(String[] args) {   int i=1,j=5,k;   int d=(int)(Math.random()*10)+1;    System.out.print("while条件下的使用:");   while(i>0){    System.out.print(i+" ");    i++;    if(i==11)     break;   }   System.out.println();   System.out.print("do while条件下的使用:");   do{    System.out.print(j+" ");    j--;    if(j==0)     break;   }while(j<5);   System.out.println();   System.out.print("for条件下的使用:");   for(k=1;k<=100;k++){    System.out.print(k+" ");    if(k==10){     break;    }   }   System.out.println();   System.out.print("switch条件下的使用:");   switch(d){   case 1:    System.out.println("beautiful");    break;   case 2:   case 3:   case 4:   case 5:   case 6:    System.out.println("ugly");    break;   case 7:    System.out.println("I love you!");    break;   default:    System.out.println("so so...");    }  } }

转载请注明原文地址: https://www.6miu.com/read-1100188.html

最新回复(0)