자바 코딩
-
게시물 수정 , 삭제는 로그인 필요
Do #21(Dice Game) ... similar to p. 252 which uses the Random class BUT you need to put it into a loop for 10 times and keep count of how many times each player wins and the number of ties.
Then after the loop, tell me how many times player 1 won, player 2 won, and who the grand winner is overall.
선생님에게 이렇게 왔거든요 p. 252 는 밑에 제가 코딩을 복사해 놓을 건데 과제를 풀지를 못하겠어요 도와주세요 급해요 ㅠ
import java.util.Scanner;
import java.util.Random;
/**
This program simulates the rolling of dice.
*/
public class RollDice2
{
public static void main(String[] args)
{
String again = "y"; // To control the loop
int die1; // To hold the value of die #1
int die2; // to hold the value of die #2
// Create a Scanner object to read keyboard input.
Scanner keyboard = new Scanner(System.in);
// Create a Random object to generate random numbers.
Random rand = new Random();
// Simulate rolling the dice.
while (again.equalsIgnoreCase("y"))
{
System.out.println("Rolling the dice...");
die1 = rand.nextInt(6) + 1;
die2 = rand.nextInt(6) + 1;
System.out.println("Their values are:");
System.out.println(die1 + " " + die2);
System.out.print("Roll them again (y = yes)? ");
again = keyboard.nextLine();
}
}
}
이거를 바탕으로 비슷하게 이용하여 만들어야 해요 도와주세요 내공 많이 드릴께요~
#자바 코딩 #자바 코딩테스트 #자바 코딩 연습 사이트 #자바 코딩테스트 벼락치기 #자바 코딩 프로그램 #자바 코딩 사이트 #자바 코딩테스트 문법 #자바 코딩 컨벤션 #자바 코딩테스트 책 #자바 코딩테스트 책 추천