[Solved] Java number sign and asterisk [closed]


You need to keep printing space in inner loop and once it come out from the inner loop print * and/or # accordingly.

    Scanner in = new Scanner(System.in);        

    int x=0;

    System.out.println("Enter number: ");
    x = in.nextInt();

    for(int i=1;i<=x;i++){

        for(int j=1;j<=i;j++){
           System.out.print(" ");   
        }

        if(i%2==1)
        {
           System.out.println("*");
        }else
        {
           System.out.println("#"); 
        }
    }

>>>Demo Link<<<

0

solved Java number sign and asterisk [closed]