Monday, January 18, 2016

How to take input from keyboard using java

How to take input from keyboard using java - If you are a new java language learner as like me then this post will help you to learn quickly. Today we are going to share how to take integer input from keyboard in java programming language. After this tutorial you will be able to read input from keyboard in java.
How to take input from keyboard using java

How to take integer input from keyboard in java

If you don't know about java then read about java programming language that will be easier to get idea from java official site and if you have not seen my last posts on java then check programming section. At first learn how to install jdk in our local machine and then you need to check first java program here.

So, let's start our today's topic java read input from keyboard scanner or you can say java input from keyboard to string. Write a file with the name second.java on the jdk directory as we shown you in last post about java first java program tutorial linked above check out.
How to take input from keyboard using java

To copy the code just double click on it


import java.io.*;
class second{
public static void main(String args[])throws IOException{
Integer roll;
String s1;
InputStreamReader in=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(in);
System.out.print("Enter your roll number");
s1=br.readLine();
roll=Integer.valueOf(s1);
System.out.print("My roll number is"+roll);
}
}

If you have already made the file second.java then open it with notepad or any other code editor now paste the above code and save it. Now open the command promote file and type javac second.java and press enter is there is no wrong on your code there will be no error if you copy the code that won't error so now type java second and press enter.
How to take input from keyboard using java

Here you can see this program saying to type your class roll and you should enter value from your keyboard and then press enter and it will print your roll number on screen and this is one of type java input from keyboard example. so just check java input code and then  you got the way for java keyboard listener and your program is going to listen your keyboard.


You Like It, Please Share This Article Using...




Don't Forget To Read This Also...




No comments :

Speak Your Mind: