LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-15-2003, 02:59 AM   #1
Schizo265
Member
 
Registered: Nov 2002
Distribution: Slackware 8.1, 9.0
Posts: 44

Rep: Reputation: 15
simple java question?


how do i handle input on an integer?

in this book my friend lent me, i read that i could use this and it would work.


import java.io.*;

public class RectDrawer
{
static BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter screen = new PrintWriter(System.out,true);

public static void main(String[] args)
{
int i,j,rows,cols;


screen.println("Enter the dimension of the rectangle.");
screen.print("columns?"); screen.flush();
*cols = new Integer(keyboard.readLine()).intValue();
screen.print("rows?"); screen.flush();
*rows = new Integer(keyboard.readLine()).intValue();

screen.println("This will have three rows and three columns\n");
for (i=0;i<cols;i++) screen.print(" "+"_"); screen.println(" ");
for (j=0;j<rows;j++)
{
for (i=0;i<cols;i++) screen.print("|"+"_"); screen.println("|");
}

}
}


i put * on the lines im having trouble with. i get errors here:

Error: cannot resolve symbol
symbol : method intValue ()
location: class java.lang.String

and this one:

Error: unreported exception java.io.IOException; must be caught or declared to be thrown

argh. programming n00b. help me out.
 
Old 07-15-2003, 04:11 AM   #2
Bill_Tür
Member
 
Registered: Jul 2003
Location: Germany
Distribution: RedHat
Posts: 44

Rep: Reputation: 15
public static void main(String[] args) throws IOException

Try this and it you get no compiler errors. There are checked and unchecked Exception. Checked Ecxeptions must be caught or thrown. Everything that deals with I/O is a checked Exception. The compiler reports an error if you didn't catch or throw an checked Exception.
 
Old 07-15-2003, 04:20 AM   #3
Bill_Tür
Member
 
Registered: Jul 2003
Location: Germany
Distribution: RedHat
Posts: 44

Rep: Reputation: 15
Oh I forgot your first error message.

cols = (new Integer(keyboard.readLine())).intValue();

Should work. Better is the following solution. You need no Integer Object. Just use a static Method.

cols = Integer.parseInt(keyboard.readLine());
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Ubuntu Fluxbox simple question, simple answer? generallimptoes Linux - Software 3 09-26-2005 02:03 PM
A simple question:how to compile java applet in linux? nickhx Programming 5 08-11-2004 03:11 AM
Installing Programs - A simple question from my simple mind jmp875 Linux - Newbie 6 02-18-2004 09:03 PM
Simple Java question Citizen Bleys Programming 6 04-04-2002 02:16 PM
simple question seeking simple answer enzo250gto Linux - Newbie 1 10-27-2001 04:08 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration