Write Java statements that output Democrat if the party affiliation code is 'D', Republican if the party affiliation code is 'R; and independent otherwise.
import java.util.Scanner;
public class Q184229 {
/***
* Main method
* @param args
*/
public static void main(String[] args) {
Scanner input =new Scanner(System.in);
System.out.print("Enter affiliation code: ");
char affiliationCode=input.nextLine().toUpperCase().charAt(0);
if(affiliationCode=='D'){
System.out.println("Democrat");
}else if(affiliationCode=='R'){
System.out.println("Republican");
}else{
System.out.println("Independent");
}
input.close();
}
}
Comments
Leave a comment