I`m a java newbie.... I`m writing a program, where in `m suppossed to ask the user to enter the values...and store them in arr[0][0], arr[0][1] , arr[1][0], arr[1][1]...

I`m not sure how to do it.......

Any help would be appreciated.

Posted by admin (Graham Ellis), 24 November 2005

Are you asking about how to set up the 2D array, how to write loops to go though each of the elements, or how to read from the user? If the latter, are you using a stand alone application of an applet, or are you writing a server application based on Servlets of JSPs?

Sorry about all the questions - but there's a lot of possible answers.

Our Java Training Notes site may provide you with some background too - we've published our complete 5 day Java course there in .pdf files.

Posted by admin (Graham Ellis), 24 November 2005

Ah - just noticed that you title said "from command prompt". OK - have a look at the wellreader class in the notes that I've given you a link to. And the source code is in our resource centre if you want to see it and grab a copy;.

Posted by anonymous (anonymous), 24 November 2005

I`m asking the user to enter the 4 co-ordinates of rectangle for an array..............Also how do i get the float values from user.....

try {// The prompt isn't very explanatory and your users may not// realise they have to enter four numbers, space separated. System.out.println("Enter the co-ordinates for people"); String inline = standard.readLine(); while((standard.readLine()) != null) {// Next line needs to be inside the loops to get tokens int var = Integer.parseInt(inline); StringTokenizer strtok = new StringTokenizer (inline," ");// hasMoreTokens runs on the tokenizer object not the string// If you always have four tokens, 4 assignments may do better// If it might expand later, use two nested loops.// See String Tokenizer example while (inline.hasMoreTokens()) { arr[0][0]=var; arr[0][1]=var; arr[1][0]=var; arr[1][1]=var; }// Float.parseFloat for a floating point number. We've used parseFloat in an example elsewhere. b = Integer.parseInt(inline); c = Integer.parseInt(inline); d = Integer.parseInt(inline);