Advertisement
cesarnascimento

triangulo *

May 16th, 2017
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. package ex22;
  2. import java.util.Scanner;
  3.  
  4. public class ex2 {
  5.  
  6.     public static void main(String[] args) {
  7.         int alt; // a altura do triangulo
  8.         Scanner sc = new Scanner(System.in);
  9.         System.out.println("altura");
  10.         alt = sc.nextInt();
  11.         for(int i=0; i<alt; i++){
  12.             for(int j=0; j< (1+((alt-1)*2))*2-1; j++){
  13.                 //a primeira linha tem 1 * (1+)
  14.                 //a cada uma das outras linha se adiciona + 2 * ((alt-1)*2)
  15.                 //a cada * tem um espaรงo (*2)
  16.                 //o ultimo * nรฃo leva espaรงo (-1)
  17.                 if((((alt-1)*2))>=j-(i*2) && (((alt-1)*2))<=j+(i*2)){
  18.                     if(j%2==0){
  19.                         System.out.print("*");
  20.                     }else{
  21.                         System.out.print(" ");
  22.                     }
  23.                 }else{
  24.                     System.out.print(" ");
  25.                 }
  26.             }
  27.             System.out.println();
  28.         }
  29.            
  30.        }
  31.        
  32.  
  33.     }
  34.  
  35.  
  36. //  triangulo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement