Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

read( ) vs. readln( )

  Asked By: Nicole    Date: Mar 17    Category: Java    Views: 1913
  

I'm a Java novice with a little problem. My program reads a string, then a
character, then a string from the keyboard. On

the second string the program fails to pause for keyboard input. The problem
goes away if the character reading code is

commented out. The code follows. What am I doing wrong? The code follows.


import java.io.*;

class Whatever
{
public static void main( String [] args ) throws IOException
{
BufferedReader in = new BufferedReader( new
InputStreamReader(System.in));

/* Read first string */

System.out.print( "Enter any number: " );
String input = in.readLine();
double num1 = Double.parseDouble( input );


/* Read a character */

System.out.print( "Enter a letter: " );
char letter = ( char ) in.read();
System.out.println( letter );


/* Read second string */

System.out.print( "Enter an integer " );
input = in.readLine();
System.out.println( input );

int num2 = Integer.parseInt( input );

} // end method main
} // end class PayCalculator

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on read( ) vs. readln( ) Or get search suggestion and latest updates.




Tagged: