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+1)/2); i++){
- for(j = 0; j <((n+1)/2)-i ; j++) System.out.print(" ");
- for(j = 0; j < i; j++) System.out.print("* ");
- System.out.println();
- }
- for(i = 1; i < ((n+1)/2); i++){
- for(j = 0; j < i; j++) System.out.print(" ");
- for(j = 0; j < ((n+1)/2)-i; j++) System.out.print("* ");
- System.out.println();
- }
- }
- }
- /*Output:-
- Enter the number of rows: 9
- *
- * *
- * * *
- * * * *
- * * * * *
- * * * *
- * * *
- * *
- *
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement