series123
Write a program to print the series .
import java.util.Scanner; class Switch_case_1 { public static void main() { System.out.println("Press 1 or 2"); Scanner in = new Scanner(System.in); System.out.println("Press 1 for the following pattern - 12345 ; 1234 ; 123 ; 12 ; 1"); System.out.println("Press 2 for the following pattern - 99999 ; 8888 ; 777 ; 66 ; 5" ); int x=in.nextInt(); if(x==1||x==2) System.out.println("Correct input"); else { System.out.println("Wrong input"); System.exit(0); } System.out.println("enter number of rows"); int row=in.nextInt(); switch(x) { case 1 : for(int i=0;row>i;i++) { for(int j=i;j<row;j++) System.out.print(9-j); System.out.println(); } break; case 2 : for(int i=0;row>i;i++) { for(int j=i;j<row;j++) System.out.print(9-i); System.out.println(); } break; } } }
Comments
Post a Comment