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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

Java黑皮书课后题第4章:*4.10(猜测生日)改写程序清单4-3,提示用户输入字符Y代表“是”N代表“否”,代替之前输入1表示“是”,0表示“否

發布時間:2024/7/23 java 26 豆豆

*4.10(猜測生日)改寫程序清單4-3,提示用戶輸入字符Y代表“是”N代表“否”,代替之前輸入1表示“是”,0表示“否

  • 題目
    • 題目描述
    • 程序清單4-3
  • 本題代碼

題目

題目描述

*4.10(猜測生日)改寫程序清單4-3,提示用戶輸入字符Y代表“是”N代表“否”,代替之前輸入1表示“是”,0表示“否

程序清單4-3

import java.util.Scanner;public class qingdan {public static void main(String[] args) {String set1 =" 1 3 5 7\n" +" 9 11 13 15\n" +"17 19 21 23\n" +"25 27 29 31";String set2 =" 2 3 6 7\n" +"10 11 14 15\n" +"18 19 22 23\n" +"26 27 30 31";String set3 =" 4 5 6 7\n" +"12 13 14 15\n" +"20 21 22 23\n" +"28 29 30 31";String set4 =" 8 9 10 11\n" +"12 13 14 15\n" +"24 25 26 27\n" +"28 29 30 31";String set5 ="16 17 18 19\n" +"20 21 22 23\n" +"24 25 26 27\n" +"28 29 30 31";int day = 0;// Create a ScannerScanner input = new Scanner(System.in);;// Prompt the user to answer questionsSystem.out.println("Is your birthday in Set1?\n");System.out.println(set1);System.out.println("\nEnter 0 for No and 1 for Yes:");int answer = input.nextInt();if(answer == 1)day += 1;// Prompt the user to answer questionsSystem.out.println("\nIs your birthday in Set2?\n");System.out.println(set2);System.out.println("\nEnter 0 for No and 1 for Yes:");answer = input.nextInt();if(answer == 1)day += 2;// Prompt the user to answer questionsSystem.out.println("\nIs your birthday in Set3?\n");System.out.println(set3);System.out.println("\nEnter 0 for No and 1 for Yes: ");answer = input.nextInt();if(answer == 1)day += 4;// Prompt the user to answer questionsSystem.out.println("\nIs your birthday in Set3?\n");System.out.println(set4);System.out.println("\nEnter 0 for No and 1 for Yes: ");answer = input.nextInt();if(answer == 1)day += 8;// Prompt the user to answer questionsSystem.out.println("\nIs your birthday in Set3?\n");System.out.println(set5);System.out.println("\nEnter 0 for No and 1 for Yes: ");answer = input.nextInt();if(answer == 1)day += 16;System.out.println("\nYour birthday is " + day + "!");} }

本題代碼

import java.util.Scanner;public class Test4_10 {public static void main(String[] args) {String set1 =" 1 3 5 7\n" +" 9 11 13 15\n" +"17 19 21 23\n" +"25 27 29 31";String set2 =" 2 3 6 7\n" +"10 11 14 15\n" +"18 19 22 23\n" +"26 27 30 31";String set3 =" 4 5 6 7\n" +"12 13 14 15\n" +"20 21 22 23\n" +"28 29 30 31";String set4 =" 8 9 10 11\n" +"12 13 14 15\n" +"24 25 26 27\n" +"28 29 30 31";String set5 ="16 17 18 19\n" +"20 21 22 23\n" +"24 25 26 27\n" +"28 29 30 31";int day = 0;// Create a ScannerScanner input = new Scanner(System.in);;// Prompt the user to answer questionsSystem.out.println("Is your birthday in Set1?\n");System.out.println(set1);System.out.println("\nEnter N for No and Y for Yes:");String str = input.nextLine();char answer = str.charAt(0);if(answer == 'Y')day += 1;// Prompt the user to answer questionsSystem.out.println("\nIs your birthday in Set2?\n");System.out.println(set2);System.out.println("\nEnter 0 for No and 1 for Yes:");str = input.nextLine();answer = str.charAt(0);if(answer == 'Y')day += 2;// Prompt the user to answer questionsSystem.out.println("\nIs your birthday in Set3?\n");System.out.println(set3);System.out.println("\nEnter 0 for No and 1 for Yes: ");str = input.nextLine();answer = str.charAt(0);if(answer == 'Y')day += 4;// Prompt the user to answer questionsSystem.out.println("\nIs your birthday in Set3?\n");System.out.println(set4);System.out.println("\nEnter 0 for No and 1 for Yes: ");str = input.nextLine();answer = str.charAt(0);if(answer == 'Y')day += 8;// Prompt the user to answer questionsSystem.out.println("\nIs your birthday in Set3?\n");System.out.println(set5);System.out.println("\nEnter 0 for No and 1 for Yes: ");str = input.nextLine();answer = str.charAt(0);if(answer == 'Y')day += 16;System.out.println("\nYour birthday is " + day + "!");} }

總結

以上是生活随笔為你收集整理的Java黑皮书课后题第4章:*4.10(猜测生日)改写程序清单4-3,提示用户输入字符Y代表“是”N代表“否”,代替之前输入1表示“是”,0表示“否的全部內容,希望文章能夠幫你解決所遇到的問題。

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