How I really like programming, and I like programming in my free time, so I tried to create code in which the output would look like x. Something like that.
x x
x x
x
x x
x x
So, I wanted the user to enter the height "x". This is the code that I have, and I really don't know how to move on. I just need a hint, or can someone tell me where I was wrong.
import java.util.Scanner;
public class x{
public static void main(String[] args){
Scanner kbd = new Scanner(System.in);
int height;
System.out.print("Enter the height of the X: " );
height = kbd.nextInt();
for (int i = 1; i <= height; i++){
for (int j = 1; j <= height; j++) {
if(i ==j || j+i == height + 1)
System.out.println("x");
else
System.out.print(" ");
}
}
}
}
source
share