Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Integer.toString.......

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ) );
}
}
 
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
    Bookmark Topic Watch Topic
  • New Topic