jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Trying to print a 2-dimensional table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Trying to print a 2-dimensional table" Watch "Trying to print a 2-dimensional table" New topic

Trying to print a 2-dimensional table

deb uebersetzig

Joined: Sep 29, 2000
Posts: 6
I am trying to print a value from the table,I am not coverting my Char and I can't get a clean compile...what am I doing wrong?
public class Schedule
public static void main(String[] args) throws Exception
String[][] id =
{ {"CIS 115 Th 1:30"},
{"CIS 120 Mo 10:30"},
{"CIS 125 We 9:30"},
{"CIS 130 Mo 8:30"} };

char course;
int x, y, courseId;
System.out.print("Enter course ID-number 0-3, ");
course = (char)System.in.read();
for(x = 0; x < 4; ++x)
for(y = 0; y < 1; ++y)
courseId = Character.getNumericValue(course);
if(courseId == id[x][y])
System.out.println("The course name, day and time are " + id[x][y]);
greg clarke

Joined: Oct 06, 2000
Posts: 25
The compile error is because you are comparing an int to a String in the line: if ( courseId == id[x][y] ). The compile error tries to explain that in its own way.
Your code compiled when I replace id[x][y] with 1 (any int would do) and when I initialised courseId and y to 0. I know this doesn't make the program work properly, but it shows what is causing the compile error.
I'm still not sure what your algorithm is exactly, though it seems to me you want to index the course information to retrieve it by course id. If so, you may need to look at your array design.
For example, if the array index is the course id, then you only need a single dimensional array. And in fact you only initialise one dimension of the array anyway.
(You could also look at a collection type that better suits your program, but that may cloud the issue at this stage. And its probably better to come to terms with arrays first.)
Let us know how it goes.
I agree. Here's the link: http://aspose.com/file-tools
subject: Trying to print a 2-dimensional table
It's not a secret anymore!