Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

how to get input from console

  Asked By: Adella    Date: Sep 06    Category: Java    Views: 727
  

I am having problem in getting input from the command prompt into my java

application





1) i am using the following code





for(i=1;i<=10;i++)

{

int ans;

BufferedInputStream in=new BufferedInputStream(System.in);
System.out.println("this is Question ("+ i +") Please tell me your

answer");

ans=in.read();

System.out.println("you have Entered....."+ans);

}



problem 1 program prompt only for 9 times and takes first input itself

as "13"

problem 2 how to convert ascii values into actual numbers like when i

enter 1 on key board it shows me 51 and so on i want to get "1" into

variable ans instead of "51"

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Joyce Edwards     Answered On: Sep 06

// method to handle key  - down events
public boolean keyDown (Event e, int key)
{
System.out.println ("Charakter: " + (char)key + "

Integer Value: " + key);
return true;

}

if you run this in a browser look for a consol if you
run this in a command  line key should appear

 
Answer #2    Answered By: Adel Fischer     Answered On: Sep 06

Here is an answer for your 2nd question  regarding that
ascii conversion

// method to handle key  - down events
public boolean keyDown (Event e, int key)
{

//print out the ascii  - value if a key is
pressed.
System.out.println ("Charakter: " +
(char)key + " Integer Value: " + key);
}

// DON'T FORGET (although it has no meaning
here)
return true;

}

 
Didn't find what you were looking for? Find more on how to get input from console Or get search suggestion and latest updates.




Tagged: