Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.io.IOException;
- class PatternOne{
- static int getInput(String prompt){
- System.out.print(prompt);
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- while(true){
- try{
- return Integer.parseInt(br.readLine());
- } catch(IOException | NumberFormatException nfe){
- System.out.print("Exception in input! Try again: ");
- }
- }
- }
- public static void main(String args[]){
- int i, j, n = getInput("Enter the number of rows: ");
- for(i = 1; i <= n; i++){
- for(j = 1; j <= i; j++) System.out.print(j);
- for(j = 0; j < (n*2-i*2); j++) System.out.print(" ");
- for(j = i; j > 0; j--) System.out.print(j);
- System.out.println();
- }
- }
- }
- //Output:-
- // Enter the number of rows: 6
- // 1 1
- // 12 21
- // 123 321
- // 1234 4321
- // 12345 54321
- // 123456654321
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement