好文档就是一把金锄头!
欢迎来到金锄头文库![会员中心]
电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

流程控制习题.docx

6页
  • 卖家[上传人]:第***
  • 文档编号:33380700
  • 上传时间:2018-02-15
  • 文档格式:DOCX
  • 文档大小:18.84KB
  • / 6 举报 版权申诉 马上下载
  • 文本预览
  • 下载提示
  • 常见问题
    • 1.利用巢狀判定敘(if)述判定閏年.1.1 請先畫出決策圖.提示:定義一個 Data Type 為 int 的變數 theyear.先判定可否被 4 整除再判定可否被 4 和 100 整除再判定可否被 4 和 100 和 400 整除1.2 寫出程式2.利用判定敘述(switch)判定季節.2.1 請先畫出決策圖.提示:定義一個 Data Type 為 int 的變數 month.month 為 1,2,3 時是春天month 為 4,5,6 時是夏天month 為 7,8,9 時是秋天month 為 10,11,12 時是冬天3.算出 1 到 99 偶數的總合3.1 用 for3.2 用 while4.印出九九乘法表結果要如下圖1X1=1 2X1=2 3X1=3 ....1X2=2 2X2=4 3x2=6 .......5.運用輾轉相除法求最大公因數提示:兩數相除得一餘數餘數為 0,則找到最大公因數如果餘數不為零,則將分母變分子,餘數變分母, 直到相除餘數為 01.public class Year {public static void main(String[] args) {// TODO Auto-generated method stubwhile(1<2){@SuppressWarnings("resource")Scanner sc = new Scanner(System.in); System.out.println("Please input the year:");int theyear =sc.nextInt();if(theyear%4 == 0){System.out.println(theyear + "是闰年");}else if(theyear%100 == 0){System.out.println(theyear + "是闰年");}else if(theyear%400 == 0){System.out.println(theyear + "是闰年");}else System.out.println(theyear + "不是闰年");}}}2. package sea;import java.util.Scanner;public class Season {public static void main(String[] args) {// TODO Auto-generated method stubwhile(1<2){@SuppressWarnings("resource")Scanner sc = new Scanner(System.in); System.out.println("请输入月份:");int month =sc.nextInt();switch(month){case 1:case 2:case 3:System.out.println(month + "月是春天" );break;case 4:case 5:case 6:System.out.println(month + "月是夏天" );break;case 7:case 8:case 9:System.out.println(month + "月是秋天" );break;case 10:case 11:case 12:System.out.println(month + "月是冬天" );break;default:System.out.println("请重新输入! ");}}}}3.1package sum;public class Sum {public static void main(String[] args) {// TODO Auto-generated method stubint esum = 0;for(int i = 0;i < 99;i += 2){esum = esum + i;}System.out.println(esum);}}3.2package sum;public class Sumw {public static void main(String[] args) {// TODO Auto-generated method stubint esum = 0;int i =0;while(i <99){esum = esum + i;i = i+2;}System.out.println(esum);}}4.package table;public class Table {public static void main(String[] args) {// TODO Auto-generated method stubfor(int i=1;i<=9;i++){for(int j=1;j<=9;j++)System.out.print(""+j+"*"+i+"="+(j*i)+"\t");System.out.println();}}}5.package factor;import java.util.Scanner;public class Factor {public static void main(String[] args) {// TODO Auto-generated method stubwhile(1<2){System.out.println("请输入两个数:" );Scanner s = new Scanner(System.in); int x = s.nextInt();int y = s.nextInt();System.out.println("最大公因数为:" +fac(x,y));//System.out.println(x + y);}}static int fac(int m,int n){while(m%n!=0){int tmp=n;n=m%n;m=tmp;}return n;}}。

      点击阅读更多内容
      关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
      手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
      ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.