• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Read from character statement

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
}
 
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
You can't expect to wield supreme executive power just because
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic