Created
September 19, 2011 20:37
-
-
Save anonymous/1227536 to your computer and use it in GitHub Desktop.
all instances of String "name" and int "secondDenom": local variable name may not have been initialized
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Money { | |
public static void main (String args[]) { | |
Scanner sc= new Scanner(System.in); | |
String name, secondName; //Name is for the first branch, etc. | |
int nameOrDenom, firstDenom, secondDenom; //firstDenom is for the first branch, etc. | |
System.out.print("Type 1 to enter a last name, 2 to enter a denomination: "); | |
nameOrDenom= sc.nextInt(); | |
if (nameOrDenom == 1) { | |
System.out.println("Enter a name: "); | |
name= sc.next(); | |
}else if (nameOrDenom == 2) { | |
System.out.println("Enter a denomination: "); | |
secondDenom= sc.nextInt(); | |
}else System.out.println("Invalid input value!"); | |
if (name.equals("Jefferson") || name.equals("Jackson") || name.equals("Grant")) { | |
System.out.println("What denomination does " + name + " appear on? "); | |
firstDenom= sc.nextInt(); | |
if((name.equals("Jefferson") && firstDenom == (2) || | |
(name.equals("Jackson") && firstDenom == (20) || | |
(name.equals("Grant") && firstDenom == (50))))) | |
System.out.println("Right!"); | |
else System.out.println("Wrong!"); | |
}else System.out.println("Invalid name!"); | |
if (secondDenom == 2 || secondDenom == 20 || secondDenom ==50) { | |
System.out.println("Who is on the " + secondDenom +" dollar bill?"); | |
secondName= sc.next(); | |
if (secondDenom == 2 && secondName.equals("Jefferson") || | |
secondDenom == 20 && secondName.equals("Jackson") || | |
secondDenom == 50 && secondName.equals("Grant")) | |
System.out.println("Right!"); | |
else System.out.println("Wrong!"); | |
} | |
else { System.out.println("Invalid choice!"); } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment