Pattern Printing V
Description
Given an integerN
, and a pattern. Print the pattern as given in the sample I/O.
Note
: Please check for spaces.
Input
The first and the only line of the input contains the value ofN
.
Constraints
1 <=N
<= 25
Output
Print the pattern as given in the sample test case.
Hint
The following pattern is used to show the spaces that you must have in the program,_
is used to indicate the spaces.
*_*_*_*_*
*_*_*_*__
*_*_*____
*_*______
*________
Note: Underscore is only used to indicate spaces and not be printed in the actual program.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 0;i<n;i++){
for (int j=n-1-i;j>=0;j--){
if (j ==0 ){
System.out.print("*");
}else {
System.out.print("* ");
}
}
for (int k = 0 ;k<i;k++){
System.out.print(" ");
}
System.out.println();
}
}
}
No comments:
Post a Comment