完了済

This commit is contained in:
2026-10-09 16:21:02 +09:00
parent 8153c32000
commit 8c3324660c
41 changed files with 773 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
public class Question4_1 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
int num = 0;
while ( num!=5 ) {
num = (int)( Math.random()*10 );
System.out.println(num);
}
}
}

View File

@@ -0,0 +1,15 @@
public class Question4_2 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
int num = 2;
while ( num<=1000 ) {
num = num*2;
}
System.out.println(num);
}
}

View File

@@ -0,0 +1,18 @@
public class Question4_3 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
int num = 0;
while ( true ) {
num = (int)( Math.random()*10 );
System.out.println(num);
if ( num==5 ) {
break;
}
}
}
}

View File

@@ -0,0 +1,32 @@
import java.util.Scanner;
public class Question4_4 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
int map = 50;
int progress = 0;
System.out.println("===== START =====");
while ( true ) {
System.out.println("Enterキーを押してください。さいころをふります。");
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
int num = (int)( Math.random()*6+1 );
System.out.println(num+"の目が出ました。");
progress = progress + num;
if ( map-progress<=0 ) { break; }
System.out.println("残りのマスは"+(map-progress)+"マスです。");
}
System.out.println("===== GOAL =====");
}
}

View File

@@ -0,0 +1,67 @@
import java.util.Scanner;
public class Question4_5 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
boolean winflag = false;
while ( !winflag ) {
System.out.println("じゃんけんを行います。");
System.out.println("あなたの出す手を入力してください。");
System.out.println("0:グー, 1:チョキ, 2:パー");
Scanner sc = new Scanner(System.in);
int playerHand = sc.nextInt();
switch ( playerHand ) {
case 0 :
System.out.println("あなたはグーを出しました。");
break;
case 1 :
System.out.println("あなたはチョキを出しました。");
break;
case 2 :
System.out.println("あなたはパーを出しました。");
break;
// default :
// System.out.println("不正な入力です。");
// System.exit(0);
}
int npcHand = (int)( Math.random()*3 );
switch ( npcHand ) {
case 0 :
System.out.println("相手はグーを出しました。");
break;
case 1 :
System.out.println("相手はチョキを出しました。");
break;
case 2 :
System.out.println("相手はパーを出しました。");
break;
}
if ( playerHand == npcHand ) {
System.out.println("引き分けました。");
System.out.println("");
continue;
}
if ( ((playerHand==0)&&(npcHand==2)) ||
((playerHand==1)&&(npcHand==0)) ||
((playerHand==2)&&(npcHand==1)) ) {
System.out.println("負けました。");
System.out.println("");
continue;
} else {
System.out.println("勝ちました。");
winflag = true;
}
}
}
}