The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
February 2002

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Nested For Loops

Posted by Patti on February 15, 2002 at 12:20 AM

Hi. I'm supposed to use nested for loops to place the input integer x in the correponding column #, and at the same time have the x print in the corresponding row of the input integer y.
So x = 5, y = 3 would look like:
1234567890

1
2
3 x
4
5
6
7
8
9
0
Here's my miserable attempt. What am I missing this time? You know this textbook really stinks.


import java.io.*;

public class Graph {

public static void main(String[] args) throws IOException {

BufferedReader stdin = new BufferedReader
(new InputStreamReader(System.in));

int x;
int y;

do {
System.out.println ("Enter X (1-10, or -1 to quit):");
x = Integer.parseInt (stdin.readLine());
System.out.println ("Enter Y (1-10):");
y = Integer.parseInt (stdin.readLine());

if (x != -1){
System.out.println ("\t1234567890");
System.out.print ('\t');

for (int column = 1; column <= 10; column++)
if (x == column)
System.out.println ('X');
else
System.out.print (' ');

for (int row = 1; row <= 10; row++)
if (y == row)
System.out.println ("\n1:\n2:\n3:\n4:\n5:\n6:\n7:\n8:\n9:\n0:\n");


System.out.println();

}

} while (x != -1);

}
}





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us