Quantcast
Channel: Converting an if-else-if statement into a switch statement in java - Stack Overflow
Browsing latest articles
Browse All 5 View Live

Answer by santhosh for Converting an if-else-if statement into a switch...

/* Just change choice to 1 * if you want 2 or 3 or 4 * just change the switch(2 or 3 or 4) */switch(1){ case 1: System.out.println("You selected 1."); break; case 2: case 3: System.out.println("You...

View Article



Answer by MeIr for Converting an if-else-if statement into a switch statement...

import java.util.Scanner;public class ifToSwitchConversion {public static void main(String [] args) { // Declare a Scanner and a choice variable Scanner stdin = new Scanner(System.in); int choice = 0;...

View Article

Answer by arshajii for Converting an if-else-if statement into a switch...

You probably want something like:switch (choice) { case 1: System.out.println("You selected 1."); break; case 2: case 3: // fall through System.out.println("You selected 2 or 3."); break; case 4:...

View Article

Answer by Idan Arye for Converting an if-else-if statement into a switch...

switch(choice){ case 1: System.out.println("You selected 1."); break; case 2: case 3: System.out.println("You selected 2 or 3."); break; case 4: System.out.println("You selected 4."); break; default:...

View Article

Converting an if-else-if statement into a switch statement in java

I'm having trouble turning this program from an if-else-if statement into a switch statement. Any help would be appreciated.import java.util.Scanner;public class ifToSwitchConversion { public static...

View Article

Browsing latest articles
Browse All 5 View Live




Latest Images