mardi 31 janvier 2017

Drawing exercise in java

I should do this program in java that asks me to write a program that issues a V composed of asterisks like the following picture:

        *
       *
*     *
 *   *
  * *
   *

This is the program that I created but it does not work:

import java.util.*;

public class Disegnav{
  public static void main (String [] arg){
    Scanner sc = new Scanner(System.in);
    for(int i = 5; i>0; i--){
        int k = 9, l=0, x=3;
        for(int j = 0; j<=9 ; j++){
            if(i>3 && j<k)
                System.out.print(" ");
            else
                if(j==k || i==l || i==x)
                    System.out.print("*");
                else
                    System.out.print(" ");
            k--;
            l++;
            x--;
        }
        System.out.println();
    }
  }
}

Aucun commentaire:

Enregistrer un commentaire