Hi,

I want to read an integer value from console, but my input returns the ASCII value of integer, Please Help me.

import java.io.*;

class Test{
	
	public static void main(String args[])throws IOException{
		
		BufferedInputStream br=new BufferedInputStream(System.in);
		
		System.out.println("Enter an Integer");
		
		int i=br.read();
		//int j=(int)i;
		
		System.out.print(i);
	}
}

Thanks

Here are a few examples on alternatives how to read Input from a Console :- 1,2,3.

Considering your case you might especially like the third link.

solution one pre Java 5:

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter an Integer");

String value = in.readLine();     // this line may throw IOException
int i = Integer.parseInt(value);

Solution two Java 5 and higher

import java.util.Scanner // import this class first

Scanner input = new Scanner(System.in);
System.out.println("Enter an Integer");
int i = input.nextInt();

make your pick

@stephen84s
If you don't want to answer the poor guys question then don't rather than posting links with little relevance to any of us

@stephen84s
posting links with little relevance to any of us

Sorry to intrude, but what do you mean by that?

@stephen84s sorry dude I confused your footnote for your actual post my bad.

I should probably look properly nextime

When you say: "little relevance to any of us".

But probably I misunderstood you, so never mind. Besides the OP already got enough help to solve his/her problem. Continuing this discussion might be meaningless.

Sorry if my attitude sound somehow aggressive.

@ajvaAddict
A little misunderstanding there buddy. I see your avater is a pic of ghost in the shell; you into animies in any way.

Hola back

This article has been dead for over six months. Start a new discussion instead.