Answer to Question #184229 in Java | JSP | JSF for DJDS

Question #184229

Write Java statements that output Democrat if the party affiliation code is 'D', Republican if the party affiliation code is 'R; and independent otherwise.


1
Expert's answer
2021-04-22T07:57:50-0400
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();
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog