Last active
August 29, 2015 14:07
-
-
Save zeqing-guo/c0221c7ab8ed11d268a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package lab3_2; | |
import java.util.Scanner; | |
public class Lab3_2 { | |
public static void main(String[] args) { | |
Scanner input = new Scanner(System.in); | |
System.out.print("Please enter a number(positive interger): "); | |
int n = input.nextInt(); | |
System.out.println("Your input is:\n" + n); | |
while (n < 1) { | |
System.out.println("Invalid input! \nInput a positive integer: "); | |
n = input.nextInt(); | |
} | |
String spacebar = ""; | |
String star = ""; | |
int i = 0; | |
for (int j = n; j>=1; j--) { | |
for (i = j-1; i >= 1; i--) { | |
spacebar += " "; | |
} | |
System.out.print(spacebar); | |
for (int k = 1; k <= 2 * (n-j)+1; k++) { | |
star += "*"; | |
} | |
System.out.print(star); | |
System.out.println(); | |
spacebar = ""; | |
star = ""; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment