View Single Post
  #1 (permalink)  
Old 11-06-2007, 03:32 AM
confused2000 confused2000 is offline
Member
 
Join Date: Nov 2007
Posts: 3
confused2000 is on a distinguished road
Please help... assignment for school
Write a Java program that prompts the user to enter the size of a square from 1 to 20 (inclusive) and then displays a hollow square of that size made of the character uppercase ‘X’. If the user inputs an invalid number, the program should prompt them repeatedly until their input is in the allowable range.

Examples of the output:

Enter the square size from 1 – 20: 7
XXXXXXX
X______X
X______X
X______X
X______X
X______X
XXXXXXX

Enter the square size from 1 – 20: 1
X

Enter the square size from 1 – 20: 2
XX
XX

So far i got this:

import java.util.Scanner;

public class Square1 {
public static void main(String[] args) {

Scanner keyInput = new Scanner(System.in);


int lo = 1;
int hi = 20;
int squareSize;


do
{

System.out.print("Enter the square size from 1 - 20: ");
squareSize = keyInput.nextInt();
}
while (squareSize >= lo ^ squareSize <= hi);


}
}

Last edited by confused2000 : 11-06-2007 at 03:41 AM.
Reply With Quote
Sponsored Links