First off: I am not looking for somebody to do my homework. Although it would make it easier for me in the short term, please don't "help" me by writing my code for me. I would rather lose points for being late and understanding the code than get the grade and fail later. Snippets for examples are nice but not if its the whole thing. Either an explanation or a link to somewhere that will help me will be greatly appreciated.
If this has already been discussed somewhere in the forum, I apologize, but I couldn't find it after a while of searching.
My assignment:
Write a program that asks for user input of a number and a character. The number dictates how many times the character will be output in the form of a square like the below example.
Enter number: 5
Enter Character: x
xxxxx
xxxxx
xxxxx
xxxxx
xxxxx
This is what I have so far:
package lab5a;
/**
*
* @author 24x24
*/
import java.util.Scanner;
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter the length (1 - 16) of the square side: ");
int number = keyboard.nextInt();
while ((number <= 0) || (number >=17)) { //boolean decides if input is valid
System.out.print("Your input was out of range\nEnter the length (1 - 16) of the square: ");
number = keyboard.nextInt();
}
System.out.print("What character is to be used: ");
String letter = keyboard.nextLine();
//this isnt pulling in an input for some reason but not the concern atm. Just declaring prior to loop with char letter = x;
//this is where the for loop would go, if thats what I should be using
}//end of method
}//end of main
I had some iterations of a nested for loop sequence but I can only seem to get the character to print out one at a time
x
x
x
x
until I stop the program. I am not very good with for loop logic. I know it should be something like for (declare integer; condition; increment) but I just can't seem to wrap my head around how this should tie in with what I am trying to accomplish.
Thanks for any help. Ill keep perusing google and trying to understand the awful book I paid a fortune for and if I figure out what I'm doing before someone helps me I'll post how I did it.
Thanks again,
24x24