Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Triangle {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- int level = 0;
- if(n % 2 == 0) {
- level = n / 2;
- int count = 2;
- for(int i=0; i<level; i++) {
- for(int j=0; j<count; j++) {
- System.out.print("*");
- }
- System.out.println();
- count += 2;
- }
- }
- else {
- level = n / 2 + 1;
- int count = 1;
- for(int i=0; i<level; i++) {
- for(int j=0; j<count; j++) {
- System.out.print("*");
- }
- System.out.println();
- count += 2;
- }
- }
- sc.close();
- }
- }
Add Comment
Please, Sign In to add comment