Using Java-Eclipse SDK, How can I Take 2 numbers as input
I am a beginn开发者_C百科er. Using Java-Eclipse SDK, How can I Take 2 numbers as input, print the sum? I cannot open a project! Please can some one help me, telling me step by step what to do?
Thanks.. Tanvir
Are you trying to create a Java project, take two numbers as output, and print the sum? If that is true, you should really read over some basic Java/Eclipse tutorials. I would suggest the Eclipse and Java Tutorial for Total Beginners -- it should get you started on how to create/open a project and how to use eclipse.
As for getting two numbers and printing out the sum, you should really learn Java IO and do this yourself, but a quick google search gets exactly what you want:
import java.io.*; //imports java.io class
/*
* Adds 2 integers given by the user, then prints out the sum.
* Directly copied from http://www.dreamincode.net/code/snippet492.htm, as I
* am too lazy to write this myself :)
*/
public class Add2number {
//main(): application entry point
public static void main(String[] args) throws IOException {
//set input stream
BufferedReader stdin = new BufferedReader(
new InputStreamReader(System.in));
//get numbers from user input
//asks user for 1st number, then converts it to an integer
System.out.print("Enter first integer: ");
int x = Integer.parseInt(stdin.readLine());
//asks user for 2nd number, than converts it to an integer
System.out.print("Enter second integer: ");
int y = Integer.parseInt(stdin.readLine());
//add x,y
int sum = x + y;
//Display sum of x,y
System.out.println("The sum is: " + sum);
}//ends main
}//ends addReadLine
精彩评论