Results 1 to 1 of 1
-
Addition program that displays the sum of two numbers
The Java program below reads two integers typed by a user at the keyboard, computes the sum of the values and displays the result.
Java Code:import java.util.Scanner; public class Addition { // main method begins execution of Java application public static void main( String args[] ) { // create Scanner to obtain input from command window Scanner input = new Scanner( System.in ); int number1; // first number to add int number2; // second number to add int sum; // sum of number1 and number2 System.out.print( "Enter first integer: " ); // prompt number1 = input.nextInt(); // read first number from user System.out.print( "Enter second integer: " ); // prompt number2 = input.nextInt(); // read second number from user sum = number1 + number2; // add numbers System.out.printf( "Sum is %d\n", sum ); // display sum } // end method main } // end class Addition
Similar Threads
-
jTextField Simpe Addition - how to ? - Netbeans 6.0
By jesicapalma in forum NetBeansReplies: 4Last Post: 05-24-2010, 09:21 AM -
How to execute an External Program through Java program
By Java Tip in forum java.ioReplies: 0Last Post: 04-04-2008, 02:40 PM -
Write an application that displays the numbers 1 to 4 on the same line
By toby in forum New To JavaReplies: 1Last Post: 07-23-2007, 04:33 PM -
Problem when displays in the terminal
By Felissa in forum Advanced JavaReplies: 2Last Post: 07-01-2007, 02:14 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks