Welcome! Log In Create A New Profile

Advanced

Reading an Integer - Are you kidding me!!!

Posted by Ryan Botha 
Announcements Last Post
Announcement : Programming Students at UNISA School of Computing 06/19/2019 02:01PM
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Reading an Integer - Are you kidding me!!!
April 28, 2008 12:34PM
Oh my stuff!

How difficult is it to read in a simple Integer. None of the apps in the book give you code, and i've searched for about 1/2 hour trying to find something that works on the net.

any have some code to read in an integer?

here is what i've tried...

System.In.Read()
int a = in.readInt();

Also, some code a guy wrote just to read in integers!??!
Re: Reading an Integer - Are you kidding me!!!
April 28, 2008 12:37PM
Also, this compiles, but throws an exception when running?

<code>
int i1 = Integer.parseInt(args[0]);
</code>
Re: Reading an Integer - Are you kidding me!!!
April 28, 2008 05:40PM
Ok, finally got it to work. Resorted to using arguments when running the app.
Re: Reading an Integer - Are you kidding me!!!
April 28, 2008 06:36PM
On an unrelated note...

Had to dust off COS211 - C++ Data structures to figure out Assignment 2! I'ts been like 6 months. Also, assignment 1 was so simple, Assignment 2 kinda caught me off guard! Making it through though. Also fell off my chair cheering when it compiled!

...the men in the white coats are coming now...
Anonymous User
Re: Reading an Integer - Are you kidding me!!!
April 28, 2008 07:59PM
Thats very simple compaired to assembly Language COS221. When completed 501 two times!!!!!!! I cant write a hello world;;;

I like to hack but i'm caught this time ++

But the lectures were just trying to make us think unneccesarily!!!!

After or while studying Unit4, everything becomes clear.....\No wonder why we

Learn 1st and 2nd Gen in the 5th Generation......!



The greatest nano-hACKER
CMD
Re: Reading an Integer - Are you kidding me!!!
April 28, 2008 08:46PM
Just finished question 2 and 3 (kinda 1 question anyways).

Success! Actually quite satisfied now! Spent most of the day trying to figure out COS 311, with very little progress. But i'm much more comfortable now with this module smiling smiley - hopefully I haven't jinxed it eye popping smiley

Sucks i have to work tomorrow - nooooooo
Anonymous User
Re: Reading an Integer - Are you kidding me!!!
May 03, 2008 07:36PM
Parsing Numeric Command-Line Arguments
If an application needs to support a numeric command-line argument, it must convert a String argument that represents a number, such as "34", to a numeric value. Here is a code snippet that converts a command-line argument to an int:
int firstArg;
if (args.length > 0) {
try {
firstArg = Integer.parseInt(args[0]);
} catch (NumberFormatException e) {
System.err.println("Argument must be an integer"winking smiley;
System.exit(1);
}
}

parseInt throws a NumberFormatException if the format of args[0] isn't valid. All of the Number classes — Integer, Float, Double, and so on — have parseXXX methods that convert a String representing a number to an object of their type.
Sorry, only registered users may post in this forum.

Click here to login