-2
나는 이것을 Mac에서 실행 중이며 터미널에서 컴파일하지만 Java Lab9에서 입력 한 후에는 아무 것도하지 않습니다. 아래는 내가 터미널에이 파일은 컴파일되지만 실행되지 않습니다. 왜 그런가?
Last login: Wed Nov 12 15:29:48 on ttys000
Roberts-MacBook-Pro-3:~ robertsemulka$ cd /Users/robertsemulka/Desktop
Roberts-MacBook-Pro-3:Desktop robertsemulka$ javac Lab9.java
Roberts-MacBook-Pro-3:Desktop robertsemulka$ java Lab9
// 컴파일을 넣어하지만이 프로그램은 귀하의 의견을 기다리고 있습니다
import java.util.Scanner;
import java.util.Random;
public class Lab9
{
public static void main(String[] args)
{
//Create arrays
int[] lotteryNum = new int[5];
int[] userNum = new int[5];
//Create Scanner and Random objects
Scanner keyboard = new Scanner(System.in);
Random randomGenerator = new Random();
//Declare and initialize a variable to track correct digits
int numCorrectDigits = 0;
//TODO: Using a for-loop, generate 5 random numbers; store numbers in the lotteryNum array
for(int i=0;i<5;i++)
{
int randomInt = randomGenerator.nextInt(10);
lotteryNum[i] = randomInt;
}
//TODO: Using a for-loop, prompt user for 5 digits; store digits in userNum array
for(int i=0;i<5;i++)
{
int UserInt = keyboard.nextInt();
userNum[i] = UserInt;
}
//TODO: Using a for-loop, compare lotteryNum array and userNum array; increment variable numCorrectDigits
//each time you find a matching pair of corresponding numbers
for(int i=0;i<5;i++)
{
if(lotteryNum[i] == userNum[i])
numCorrectDigits++;
}
//TODO: Display the winning number and the user's number
//Example:
//The winning number is: 12771
//Your number is: 30781
System.out.print("The winning number is: ");
for(int i=0; i<5; i++)
{
System.out.println(lotteryNum[i]);
}
System.out.println();
System.out.print("Your number is: ");
for(int i=0; i<5; i++)
{
System.out.println(userNum[i]);
}
//Print a blank line
System.out.println();
//TODO: Display the number of correct digits
//Example:
//Number of correct digits is: 2
//TODO: Complete the switch statement below to display results to the user
switch(numCorrectDigits)
{
case 0:
System.out.println("Your prize is: $0.00");
case 1:
System.out.println("Your prize is: $10.00");
case 2:
System.out.println("Your prize is: $100.00");
case 3:
System.out.println("Your prize is: $1000.00");
case 4:
System.out.println("Your prize is: $10,000.00");
case 5:
System.out.println("Your prize is: $100,000.00");
break;
Why does this compile but not
}
System.out.println("\nPlease play again!");
}
}
Your program will generate a 5-digit lottery number, and then it will prompt the user to enter a guess in the form of a 5-digit number. Your program should then determine how many numbers the user guessed correctly and the user’s prize.
Your program must use an object of the Random class to generate five integers in the range 0 through 9 and must store these integers in an array.
Your program also needs to prompt the user to enter 5 integers in the range 0 through 9 and then needs to store these integers in an array.
So you will use two integer arrays in this program.
To determine how many numbers the user correctly guessed, your program needs to compare corresponding elements of both arrays in a for loop. Use a counter variable to keep track of how many numbers the user guessed correctly.
At the end of the program, output to the user the lottery number, the user’s guess, and the number of digits that the user guessed correctly.
Finally, your program needs to determine and display the user’s prize. Here is a chart that defines the prizes for this lottery:



Number of correct digits Prize

0 $0

1 $10

2 $100


3 $1,000

4 $10,000


5 $100,000
Here are some sample runs (user input is given in <>): 1.
Welcome to the Lottery Application!
Please enter a digit in the range 0-9: <3>
Please enter a digit in the range 0-9: <0>
Please enter a digit in the range 0-9: <7>
Please enter a digit in the range 0-9: <8>
Please enter a digit in the range 0-9: <1>
CS7 Lab 9
Fall 2014
The winning number is: 12771
Your number is: 30781
Number of correct digits: 2
Your prize is: $100.00!
Please play again!
5 개의 숫자를 입력 할 때까지 기다리고 있습니다. –
편집은 실행과 거의 관련이 없습니다. – user2717954
프로그램은 다섯 개의 숫자를 입력해야하며 프롬프트를 입력하거나 입력하라는 메시지를 출력하지 않습니다. 입력 했습니까? – ajb