Last active
October 25, 2017 14:45
-
-
Save neet/e512760061eea2c2040a990e1dc29ba6 to your computer and use it in GitHub Desktop.
javaQuizes2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class JavaQuizes { | |
/** | |
* Quiz 02 | |
*/ | |
public static void quiz02(String args[]) { | |
Scanner scanner = new Scanner(System.in); | |
// 月を取得 | |
System.out.println("誕生日の月を入力してください:"); | |
int month = scanner.nextInt(); | |
// 日を取得 | |
System.out.println("誕生日の日を入力してください:"); | |
int day = scanner.nextInt(); | |
if ( month == 3 ) { | |
// 月が3月で日が21日未満 | |
if ( day < 21 ) { | |
String text = "魚座"; | |
// 月が3月で日が21以上 | |
} else if ( day >= 21 ) { | |
String text = "牡羊座"; | |
} | |
} else if ( month == 4 ) { | |
if ( day < 20 ) { | |
String text = "牡羊座"; | |
} else if ( day >= 20 ) { | |
String text = "牡牛座"; | |
} | |
} else if ( month == 5 ) { | |
if ( day < 21 ) { | |
String text = "牡牛座"; | |
} else if ( day >= 21 ) { | |
String text = "双子座"; | |
} | |
} else if ( month == 6 ) { | |
if ( day < 22 ) { | |
String text = "双子座"; | |
} else if ( day >= 22 ) { | |
String text = "蟹座"; | |
} | |
} else if ( month == 7 ) { | |
if ( day < 23 ) { | |
String text = "蟹座"; | |
} else if ( day >= 23 ) { | |
String text = "獅子座"; | |
} | |
} else if ( month == 8 ) { | |
if ( day < 23 ) { | |
String text = "獅子座"; | |
} else if ( day >= 23 ) { | |
String text = "乙女座"; | |
} | |
} else if ( month == 9 ) { | |
if ( day < 23 ) { | |
String text = "乙女座"; | |
} else if ( day >= 23 ) { | |
String text = "天秤座"; | |
} | |
} else if ( month == 10 ) { | |
if ( day < 24 ) { | |
String text = "天秤座"; | |
} else if ( day >= 24 ) { | |
String text = "蠍座"; | |
} | |
} else if ( month == 11 ) { | |
if ( day < 24 ) { | |
String text = "蠍座"; | |
} else if ( day >= 24 ) { | |
String text = "射手座"; | |
} | |
} else if ( month == 12 ) { | |
if ( day < 22 ) { | |
String text = "射手座"; | |
} else if ( day >= 22 ) { | |
String text = "牡羊座"; | |
} | |
} else if ( month == 1 ) { | |
if ( day < 20 ) { | |
String text = "牡羊座"; | |
} else if ( day >= 20 ) { | |
String text = "水瓶座"; | |
} | |
} else if ( month == 2 ) { | |
if ( day < 19 ) { | |
String text = "水瓶座"; | |
} else if ( day >= 19 ) { | |
String text = "魚座"; | |
} | |
} | |
} | |
/** | |
* Quiz 03 | |
*/ | |
public static void quiz03(String args[]) { | |
Scanner scanner = new Scanner(System.in); | |
// 年を取得 | |
System.out.println("年を入力してください"); | |
int year = scanner.nextInt(); | |
// まず、4で割れるか | |
if ( year % 4 == 0 && year % 100 == 0 && year % 400 != 0) { | |
System.out.println("うるう年じゃない"); | |
} else { | |
System.out.println("うるう年だよ"); | |
} | |
} else { | |
System.out.println("うるう年じゃない"); | |
} | |
} | |
/** | |
* Quiz 05 | |
*/ | |
public static void quiz05(String args[]) { | |
Scanner scanner = new Scanner(System.in); | |
System.out.println("正の整数を入力してください"); | |
int number = scanner.nextInt(); | |
int count = 1; | |
while ( count < number ) { | |
count = count + 2; | |
System.out.println(count); | |
} | |
} | |
/** | |
* Quiz 06 | |
*/ | |
public static void quiz06(String args[]) { | |
Scanner scanner = new Scanner(System.in); | |
System.out.println("正の整数を入力してください:"); | |
int number = scanner.nextInt(); | |
int count = 1; // ループカウント | |
int sum = 0; // 3または5の倍数の合計 | |
while ( count < number ) { | |
// 3の倍数か (3で割ってあまりが出ない数字) | |
// あるいは5の倍数か (5で割ってあまりが出ない数字) | |
if ( count % 3 == 0 || count % 5 == 0 ) { | |
sum = sum + 1; | |
} | |
count = count + 1; //ループの最後に無条件で1を足すことで次の数字へ | |
} | |
System.out.println("3の倍数または5の倍数の合計は"+sum+"です"); | |
} | |
/** | |
* Quiz 07 | |
*/ | |
public static void quiz07(String args[]) { | |
Scanner scanner = new Scanner(System.in); | |
System.out.println("1個目の整数:"); | |
int number1 = scanner.nextInt(); | |
System.out.println("2個目の整数:"); | |
int number2 = scanner.nextInt(); | |
if ( number1 < number2 ) { | |
int primaryNumber = number1; | |
int secondaryNumber = number2; | |
} else { | |
int primaryNumber = number2; | |
int secondaryNumber = number1; | |
} | |
int sum = 0; | |
int count = primaryNumber; | |
while ( count <= secondaryNumber ) { | |
sum = sum + 1; | |
count = count + 1; | |
} | |
System.out.println(primaryNumber+"以上"+secondaryNumber+"以下の整数の和は"+sum+"です"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
n = n + 1;
をn++;
としないのはわざと