자바 코딩

자바 코딩

작성일 2024.02.25댓글 1건
    게시물 수정 , 삭제는 로그인 필요

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();
      }
   }
}

이거를 바탕으로 비슷하게 이용하여 만들어야 해요 도와주세요 내공 많이 드릴께요~


#자바 코딩 #자바 코딩테스트 #자바 코딩 연습 사이트 #자바 코딩테스트 벼락치기 #자바 코딩 프로그램 #자바 코딩 사이트 #자바 코딩테스트 문법 #자바 코딩 컨벤션 #자바 코딩테스트 책 #자바 코딩테스트 책 추천

profile_image 익명 작성일 -

주어진 코드를 기반으로 주사위 게임을 10번 반복하고,

각 플레이어의 승리 횟수와 무승부 횟수를 계산하여 최종 승자를 알려주는 자바 코드를 작성하겠습니다.

```java

import java.util.Random;

public class RollDiceGame {

public static void main(String[] args) {

int player1Wins = 0; // To hold the number of wins for player 1

int player2Wins = 0; // To hold the number of wins for player 2

int ties = 0; // To hold the number of ties

// Create a Random object to generate random numbers.

Random rand = new Random();

// Play the game 10 times

for (int i = 0; i < 10; i++) {

int player1Die = rand.nextInt(6) + 1;

int player2Die = rand.nextInt(6) + 1;

if (player1Die > player2Die) {

player1Wins++;

} else if (player2Die > player1Die) {

player2Wins++;

} else {

ties++;

}

}

// Print the results

System.out.println("Player 1 wins: " + player1Wins);

System.out.println("Player 2 wins: " + player2Wins);

System.out.println("Ties: " + ties);

if (player1Wins > player2Wins) {

System.out.println("The grand winner is Player 1!");

} else if (player2Wins > player1Wins) {

System.out.println("The grand winner is Player 2!");

} else {

System.out.println("It's a tie!");

}

}

}

```

이 코드는 각 플레이어의 주사위를 10번 굴린 후,

더 높은 숫자를 얻은 플레이어가 승리하도록 설정되어 있습니다.

두 플레이어가 같은 숫자를 얻게 되면 무승부로 간주합니다.

게임이 끝난 후에는 각 플레이어의 승리 횟수와 무승부 횟수, 그리고 최종 승자를 출력합니다.

자바 코딩

자바 아래처럼 조건 맞추는 코딩을 알려주세요 " "" "" "" "" "" " "" 이렇게 만드시면 되겠습니다.

자바 코딩 환경 구축

에디트노트로 자바 코딩 환경을 구축 하고 싶은데 아무리해도 모르겠네요.. 자세하게 알려주실수 있나요.. 혼자 어떻게든 했는데 자꾸 컴파일 출력 에러가 납니다.....

자바 코딩에 Scanner scanner의 차이를

자바 코딩에 Scanner scanner의 차이를 기술해주세요 Scanner는 java.util패키지 내의 클래스 이름이고요, scanner라는 건 없습니다. 변수명으로 지정할 수는 있어요.

자바 코딩에서 if (i % 2 != 0) 이걸 한글

자바 코딩에서 if (i % 2 != 0) 이걸 한글로 번역해주세요 직역하면 만약 i를 2로 나눈 나머지가 0과 같지 않다면 이고요. 쉽게 정리하면 i가 홀수라면 되겠습니다.

자바 코딩소스 해석

... System.out.println("average : " + avaerage); } } 해당 코딩 소스 중 평균 구하는 avaerage = total/(float)(arr.length * arr[0].length); 왜 이렇게 표현하는지 설명...

자바코딩추가질문

https://cafe.naver.com/minecraftgame 이전 우마공 마크 돈벌이가 이 인간인데 대강 코딩 내용 보고 어느정도 수준인지 알려주세요 전 잘모르겠네요 그냥 카페 메인 페이지로...