wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Read from character statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Read from character statement" Watch "Read from character statement" New topic
Author

Read from character statement

Mohd Zaki Mohd Salikon
Greenhorn

Joined: Dec 16, 2004
Posts: 27
Below is a subprogram. It shows the output with looping using integer keydata (while j==1).
1. How to convert the integer statement (1) to character statement ('Y')?
2. How to clearscreen the previous statement? In C language, we can insert clrscr(); with #include<conio.h>.

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

String input_jawap;
int j;
do{
//statement
input_jawap = input.readLine();
j = Integer.parseInt(input_jawap);
}while(j==1);
}
Stuart Gray
Ranch Hand

Joined: Apr 21, 2005
Posts: 410
1. How to convert the integer statement (1) to character statement ('Y')?

This is quite easy. First you need to understand what the Integer.parseInt method does. Look it up in the API docs and you will find it converts a certain type of variable into an int (look in the java.lang package).

Now you need to change your code so that instead of converting input_jawap into an int, you convert it into a character. If the Integer class is used to convert things into ints, which class might be used to convert things into characters?

You will also need to change the type of the 'j' variable too. After that you just need to make a small adjustment to the if statement so that it compares with a character instead of a number.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Read from character statement