Advertisement
taweesoft

String in Switch-case

Sep 7th, 2014
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.51 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. enum Fruit{
  4.     apple,banana,orange;
  5. }
  6. public class TaweeOne {
  7.  
  8.     public static void main(String[] args) {
  9.         Scanner scan = new Scanner(System.in);
  10.         System.out.print("Enter fruit name : ");
  11.         String fruitString = scan.nextLine();
  12.         Fruit fruit = Fruit.valueOf(fruitString);
  13.         switch(fruit){
  14.         case apple:
  15.             System.out.println("APPLE");
  16.             break;
  17.         case banana:
  18.             System.out.println("BANANA");
  19.             break;
  20.         case orange:
  21.             System.out.println("ORANGE");
  22.             break;
  23.         }
  24.     }
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement