日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java简单代码

發布時間:2023/12/9 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java简单代码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

今日學習
java簡單代碼

public class 輸入一到一百的數字判斷是不是質數{// 除了自己之和一之外不能被整除的數--質數public static void main(String[] args) {for (int i = 1; i <= 100; i++) {if (abc(i)) {System.out.println(i + "shi zhishu");} elseSystem.out.println(i + "bushizhishu");}System.out.println(abc(10));}public static boolean abc(int kk) {boolean res = true;for (int i = 2; i <= kk / 2; i++) {if (kk % i == 0) {res = false;break;}}return res;} } public class 輸入日期計算日期在本年的天數 {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int year = 0, months = 0, date = 0;while (true) {year = intputNum(sc, 1, 3000, "年份");months = intputNum(sc, 1, 12, "月份");date = intputNum(sc, 1, 30, "日期");boolean bb = validateDate(year, months, date);if (bb)break;System.out.println("請輸入正確年月日");}System.out.println(year + "-" + months + "-" + date);}public static boolean validateDate(int year, int months, int date) {boolean res = false;switch (months) {case 1:case 3:case 5:case 7:case 8:case 10:case 12:res = date >= 1 && date <= 31;break;case 4:case 6:case 9:case 11:res = date >= 1 && date <= 30;break;case 2:boolean bb = run(year);if (bb)res = date <= 29 && date >= 1;elseres = date <= 28 && date >= 1;break;default:res = false;break;}return res;}public static boolean run(int year) {return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);}public static int intputNum(Scanner sc, int min, int max, String str) {int res = 0;while (true) {System.out.println(str + ":");String ss = sc.nextLine();try {res = Integer.parseInt(ss);if (res >= min && res <= max)break;System.out.println("請輸入合理的" + str + "值"); } catch (Exception e) {System.out.println("您輸入的日期不合法");}}return res; } } import java.util.Scanner;public class 手寫兔子 {public static void main(String[] args) {int months = 0;Scanner sc = new Scanner(System.in);while (true) {System.out.println("月份");String ss = sc.nextLine();try {months = Integer.parseInt(ss);if (months > 0)break;System.out.println("請重新輸入月份");} catch (Exception e) {System.out.println("請輸入合法的月份值");}}int num = tongJi(months);System.out.println(months + "月后的兔子數為:" + num);}public static int tongJi(int months) {if (months > 0) {if ((months == 1) || (months == 2))return 1;return tongJi(months - 1) + tongJi(months - 2);}return 0;} }

總結

以上是生活随笔為你收集整理的java简单代码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。