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 Integer.toString....... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Integer.toString......." Watch "Integer.toString......." New topic
Author

Integer.toString.......

Ananth Ram
Greenhorn

Joined: Dec 07, 2001
Posts: 12
Hi folks,
just look at the following code and help me out in getting the right output for the program. I am a newbie and learning.
I am not able to get the input number as output....
Thanks
Ram

// Largest.java
import java.io.*;
public class Largest {
public static void main( String args[] ) throws IOException
{
int count = 0, counter = 1, num1, number, largest = 0;
System.out.println( "Enter 10 single digit numbers " );

while( counter <= 10 ) {
number = System.in.read();
num1 = number;
if( count == 0 ) {
largest = num1;
count = 1;
}

if( largest <= num1 )
largest = num1;
System.in.skip( 2 );
counter = counter + 1;
}

System.out.println( "Largest is: " + Integer.toString( largest ) );
}
}
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
You're getting the data correctly, you're just getting it as the integer representing the bytecode for the character typed in. Instead of trying to make a String out of the integer, just cast largest to a character using (char), you should get the results you expect.
By the way, put in a bunch of letters, it works for that too
Jason
[This message has been edited by jason adam (edited December 08, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Integer.toString.......
 
Similar Threads
Problem with Sort Method
Program Problem
Changing an arrays size
Hey Mike, I need an idea for this one
toString() method