opzoonzhuzhengke的专栏

(1) 写一个程序,打印出1 到100 间的整数。

public class test{ public static void main(String[] args){ int i; for(i=0;i<=100;i++){ //if(i==47) break; //if(i==47) return; System.out.println(i+" "); } } }

(2) 修改练习(1),在值为47时用一个break退出程序。亦可换成return试试。

(3) 创建一个switch 语句,为每一种case 都显示一条消息。并将 switch置入一个for循环里,令其尝试每一种case。在每个case 后面都放置一个break,并对其进行测试。然后,删除break,,看看会有什么情况出现。

import java.util.*;public class test{public static void main(String[] args){int month;Date now=new Date();month=now.getMonth()+1;switch(month){case 1:System.out.println("Januay");break;case 2:System.out.println("February");break;case 3:System.out.println("March");break;case 4:System.out.println("April");break;case 5:System.out.println("May");break;case 6:System.out.println("June");break;case 7:System.out.println("July");break;case 8:System.out.println("August");break;case 9:System.out.println("September");break;case 10:System.out.println("October");break;case 11:System.out.println("November");break;case 12:System.out.println("December");break;default: break;}}}

输出:

November

修改后:

import java.util.*;public class test{public static void main(String[] args){int month;Date now=new Date();month=now.getMonth()+1;switch(month){case 1:System.out.println("Januay");break;case 2:System.out.println("February");break;case 3:System.out.println("March");break;case 4:System.out.println("April");break;case 5:System.out.println("May");break;case 6:System.out.println("June");break;case 7:System.out.println("July");case 8:System.out.println("August");case 9:System.out.println("September");case 10:System.out.println("October");break;case 11:System.out.println("November");case 12:System.out.println("December");break;default: break;}}}

输出:

NovemberDecember

勇于接受自己的不完美,认清自己不足的地方,

opzoonzhuzhengke的专栏

相关文章:

你感兴趣的文章:

标签云: