File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes where to begin! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "where to begin!" Watch "where to begin!" New topic
Author

where to begin!

Mike Smith
Ranch Hand

Joined: Sep 23, 2005
Posts: 85
Hello all, I have to make a program that allows user input. I know that I will read from the console and reference a string object.For example I will use;
String a= Stdin.readln(); // where a will reference the string object. I am fine with this part. My program has to decide whether a string of characters or numbers is an integer or not. If it is a integer, It will print out this is an integer.If it isn't an integer it will pring Its not an integer. An integer must meet the following critera: numbers and no spaces and it could be a negative sign preceding numbers. If it is not an integer is must meet the following critera: characters not numbers and no spaces between them and numbers with spaces.
With this in mind I realize I can accomplish this task with an if statement and else if statements. BUt I am unsure how the charAt() String method will come into play. If anyone could point me to a start I would be greatfull. Thanks again...
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
Is it's not part of the assignment to do this the 'long' way, the Integer class
has a method to handle the requirements - you just have to wrap it in a try/catch block.
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 690
    
    1
Looks like time for a loop of some kind with code that will look at all the characters in a String. Use an int as index into the chars of the String using the charAt(int) method to obtain the individual characters so they can be tested as per the assignment. The loop should end after you look at the last character.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: where to begin!