Where are you having problems.
For reading command line I use something like this:
BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter set of values:")
String input = keyboard.readLine();
If you enter:
3 4
Then the String input will have this value: "3 4"
So you can do something like this:
import java.io.*;
class IsRecSquare
{
static int count;
public static void main(String [] args)
{
BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
do
{
System.out.println("Enter set of values:")
String input = keyboard.readLine().trim();
if (input.length != 0) {
//code for parsing input into 2 int numbers length and height
//use: StringTokenizer or String.split(), or (String.indexOf with String.subString())
if (length == height) {
count++;
}
}
} while (!input.equals(""));
System.out.println("The number of squares are : " + count);
}
}
Of course you will add the necessary try-catch block
javaAddict
Nearly a Senior Poster
Team Colleague
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448