import java io public class Demo If Else
import java. io. *; public class Demo. If. Else 2 { public static void main (String args[]) throws IOException { Buffered. Reader stdin = new Buffered. Reader(new Input. Stream. Reader(System. in)); System. out. println("Press mounth (1 - 12) "); String input = " "; input = stdin. read. Line(); int month = Integer. parse. Int(input); String season; if (month ==1 || month ==2 || month==3) season = "Medium Hot"; else if (month ==4 || month ==5 || month==6) season = "Very Hot"; else if (month ==7 || month ==8 || month==9) season = "Hard Rainy"; else if (month ==10 || month ==11 || month==12) season = "Min Hot"; else season = "ERROR"; System. out. println ("Month " + month + " = " + season ); } }
import javax. swing. *; import java. awt. *; public class Switch. Control. Swing{ public static void main (String args[]) { JFrame frame = new JFrame("Switch. . . "); JPanel panel = new JPanel(); JLabel label; Image. Icon icon; int choice =2; char img. Type ='s'; // or "i" or Other switch(img. Type){ case 's': icon = new Image. Icon("icon" + choice + ". png"); label = new JLabel("s=>"+choice , icon, JLabel. RIGHT); panel. add(label); break; case 'i': icon = new Image. Icon("icon" + choice+ ". png"); label = new JLabel("s=>"+choice , icon, JLabel. RIGHT); panel. add(label); break; default: icon = new Image. Icon("icon" + choice+ ". png"); label = new JLabel("s=>"+choice , icon, JLabel. RIGHT); panel. add(label); break; } panel. set. Background(Color. white); frame. get. Content. Pane(). add(panel); frame. set. Default. Close. Operation(JFrame. EXIT_ON_CLOSE); frame. pack(); frame. set. Visible(true); } }
- Slides: 18