The new format is this:
Choose 3 of: (0=rock, 1=paper, 2=scissors): 011
You chose <rock, paper, paper>
Computer chose <scissors, paper, rock>
import java.util.Scanner;
public class Game {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String personPlay;
String pChoice = null;
int x = (int)(Math.random()*3);
String play;
System.out.println("Chose 3 of (0=rock, 1=paper,2=scissors):");
System.out.println();
for(int i = 0; i < 3; i++){
personPlay = input.next();
if(personPlay.length() > 3 || personPlay.length() < 3)
System.out.println("Invalid Entry.");
System.exit(0);
if (Character.isDigit(personPlay.charAt(0)) & Character.isDigit(personPlay.charAt(1))
& Character.isDigit(personPlay.charAt(2))){
if(personPlay.charAt(0)==0){
pChoice = "Rock";
if(personPlay.charAt(0)==1){
pChoice = "Paper";
if(personPlay.charAt(0)==2){
pChoice = "Scissors";
}
}
}
if(personPlay.charAt(1)==0){
pChoice = "Rock";
if(personPlay.charAt(2)==1){
pChoice = "Paper";
if(personPlay.charAt(2)==2){
pChoice = "Scissors";
}
}
}
if(personPlay.charAt(3)==0){
pChoice = "Rock";
if(personPlay.charAt(3)==1){
pChoice = "Paper";
if(personPlay.charAt(3)==2){
pChoice = "Scissors";
}
}
}
System.out.println("You chose: " + pChoice);
}
else {
System.out.println("Invalid entry only use numbers from 0 to 2");
}// if
} // for
}
}
This is the code I have so far. If I could just fix this part I'm sure the rest will come easily. I figured it would be easier to read the input in as a String and then use isDigit to check for the number choices. Was I wrong?
Do I need a array for the selections instead of a for loop? In the end I think I just confused myself... Thanks in advance for any advice given.

New Topic/Question
Reply


MultiQuote




|