WAP Sandglass on Java
package HelloWorld;
import java.util.Scanner; //this is a Scanner class
public class LearningJava {
// * * * * *
// * * * *
// * * *
// * *
// *
// * *
// * * *
// * * * *
// * * * * *
public static void main (String[] args) {
Scanner scan = new Scanner(System.in); //this is my scanner
// this is for reverse pyramid
int n = scan.nextInt();
for(int i =1;i<=n;i++) { //thi is for outer loop
for(int j =1;j<=i;j++) { ///this is for spcaes
System.out.print(" ");
}
for(int k =n;k>=i;k--) {
System.out.print("* ");
}
System.out.println();
}
//this is for down pyramid
for(int i =1;i<=n;i++) {
for(int j = n;j>=i;j--) { //this is for space
System.out.print(" ");
}
for(int k =1;k<=i;k++) {
System.out.print("* ");
}
System.out.println();
}
}
}
Comments
Post a Comment