• Post Reply Bookmark Topic Watch Topic
  • New Topic

throwsjava.io.IOException  RSS feed

 
Chinedu Ezenwanne
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
trying to use the io format to write a code that allows a user punch in 8
nos b/w 0 & 9 like in a pin code
So far I've here is were I am

/* this is my first attempt at coding using throws java io
trying to see if i could mimic reload a recharge voucher on to a cellphone.
*/

class Pincode {
public static void main (String args [])
throws java.io.IOException
int codename
// Hope I'm making sense,if not could someone correct me & put me on course
thanks
 
Herb Schildt
Author
Ranch Hand
Posts: 253
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chinedu:
Here are a couple of points to help you get started.
You can read a string from the keyboard using the following sequence

To convert the string into an integer, you can use this code:

Notice that you have to catch and handle NumberFormatException, which is thrown if the string being converted into an integer does not contain a valid integer value.
One other point, although it is common in example programs to simply throw IOException out of main(), as you code does, you could also handle it inside main() by using a try/catch block similar to that required by Integer.parseInt().

If you are still having problems, let us know.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!