2010-07-30 1 views

답변

3

당신이 합계를, 자바 프로젝트를 생성 출력으로 두 개의 번호를 가지고 가고, 인쇄하려고합니까? 그것이 사실이라면, 당신은 정말로 기본적인 Java/Eclipse 튜토리얼을 읽어야합니다. 나는 Eclipse and Java Tutorial for Total Beginners을 제안 할 것이다 - 그것은 당신이 프로젝트를 만들고 어떻게 만드는지에 대한 시작과 이클립스 사용법을 익혀야한다. 두 숫자를 받고 합계를 인쇄에 관해서는

, 당신은 정말 자바 IO를 배우고 자신이 작업을 수행하지만, 빠른 구글 검색은 당신이 원하는 것을 정확히 도착해야합니다

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 
관련 문제