example that accepts two integer from the user and find their sum

example that accepts two integer from the user and find their sum

example that accepts two integer from the user and find their sum

View Answers

September 3, 2012 at 1:03 PM

Here is a java example that accepts two integer from the user and find their sum.

import java.util.*;
class AddNumbers
{
    public static void main(String[] args) 
    {
        Scanner input=new Scanner(System.in);
        System.out.print("Enter first number: ");
        int num1=input.nextInt(); 
        System.out.print("Enter second number: ");
        int num2=input.nextInt();
        int sum=num1+num2;
        System.out.println("Result is: "+sum);
    }
}









Related Tutorials/Questions & Answers:
accept integer from user
accept integer from user  Write an Java application that accepts 100 integer numbers from a user. The input should be in the range of 1-200. Error message needs to be displayed if user entered input which is not in this range
write a program which asks the user for two int values and calculates their sum.
write a program which asks the user for two int values and calculates their sum.  The title says it all, an example is (1,2) > 3
Advertisements
How to find out the friend user between two columns in sql database
How to find out the friend user between two columns in sql database  Hi, Can any one please tell me ..how to find out the friend user between two columns in sql database? In other words i wanted to get the corresponding data from
Find Cylinder area By inputting value from user
Find Cylinder area By inputting value from user  Hello Sir I need the code for calculating the area of a cylinder in which it asks radius value from user and then calculate area using this radius value. Please provide me
Merge and sum of two dictionaries
Merge and sum of two dictionaries  Hi, I want to merge the two dictionaries and at the same I want to sum the vales of the same key. How I can achieve this? Thanks   Hi, this is very classical example of summing
swap two integer arrays
swap two integer arrays  int [] array1 = {1,2,3,4,5} int [] array2 = {6,7,8,9,10} how can we swap the values of bith integer arrays results like this array1 = {6,7,8,9,10} array2 = {1,2,3,4,5
swap two integer arrays
swap two integer arrays  int [] array1 = {1,2,3,4,5} int [] array2 = {6,7,8,9,10} how can we swap the values of bith integer arrays results like this array1 = {6,7,8,9,10} array2 = {1,2,3,4,5
swap two integer arrays
swap two integer arrays  int [] array1 = {1,2,3,4,5} int [] array2 = {6,7,8,9,10} how can we swap the values of bith integer arrays results like this array1 = {6,7,8,9,10} array2 = {1,2,3,4,5
Java Matrix Addition Example
Java Matrix Addition Example In this tutorial, you will learn how to find the sum of two matrices. You may have solved many Matrix Operations in Mathematics... the sum of two matrices of any order using the java language. In the given program
A program to find the sum of odd number
the console. Now here is the simple example which will help you to find the sum of odd...A program to find the sum of odd number In this section you will learn how to find the sum of odd number in the series up to the given number in java
Find Sum of Diagonals of Matrix
elements. Here we are going to find the sum of Primary diagonal (From left top...Find Sum of Diagonals of Matrix You all know that a matrix is a rectangular...) of the matrix from the given two dimensional array. See the following matrix
find the given input is integer or string
find the given input is integer or string  simple coding for to check the given input value is integer or no.If the given value is integer display "Value is integer" otherwise "Value is not a integer"?   class
ModuleNotFoundError: No module named 'two-num-sum'
ModuleNotFoundError: No module named 'two-num-sum'  Hi, My Python... 'two-num-sum' How to remove the ModuleNotFoundError: No module named 'two-num-sum' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'two-num-sum'
ModuleNotFoundError: No module named 'two-num-sum'  Hi, My Python... 'two-num-sum' How to remove the ModuleNotFoundError: No module named 'two-num-sum' error? Thanks   Hi, In your python environment
Sum of two Matrix
Sum of  two Matrix       In this section, we are going to calculate the sum of two matrix... to this. In this program we are going to calculate the sum of two matrix. To make this program
Generate Random Integer Between Two Values in Scala
Generate Random Integer Between Two Values in Scala  Hi, I am working on the SCALA project and want to generate random integer between two numbers. How to Generate Random Integer Between Two Values in Scala? Thanks   
Generate Random Integer Between Two Values in Scala
Generate Random Integer Between Two Values in Scala  Hi, I am working on the SCALA project and want to generate random integer between two numbers. How to Generate Random Integer Between Two Values in Scala? Thanks   
Sum of two numbers using command line arguments in Java
sum = a+b; Check complete example code at Add Two Numbers in Java. Thanks...Sum of two numbers using command line arguments in Java  Hi, How to pass two values as parameter from command line and the get in it Java program
retreive integer data from database
retreive integer data from database  i made a table named result having two fields 1>rollno 2>marks i creates a gui where i use a textfield and two buttons "ok" and "cancel" i want to take input from textfield
Find sum of series
Find sum of series This section illustrates you how to find the sum of n terms... function that takes the parameter 'n' up to which the sum of the series... { public static double sum(int n) { if (n == 1) return 1.0; return sum(n - 1
how to find the sum of integers in a string of sentence in java
how to find the sum of integers in a string of sentence in java  how to find the sum of integers in a string of sentence in java for e.g:--> abc d 2 3 21 the output should be 2+3+21=26 (adsbygoogle
Find sum of all the elements of matrix using Java
Find sum of all the elements of matrix using Java A matrix is a rectangular... the following code, we have allowed the user to enter the number of rows and columns and the elements they wish to be in the matrix. These elements are stored into the two
need help with two dimensional array that takes input from user and bubble sorts and selections sorts
need help with two dimensional array that takes input from user and bubble... cannot figure out how i can declare a two dimensional array without knowing how... how many elements are going to be input by the user?   Here is a code
ask a user to enter 5 integer
ask a user to enter 5 integer  make a program that enter 5 numbers then identify the largest and the smallest number sample program 2 4 3 5 6 the smallest number: 2 the largest number: is 6 66
Two user chess game - Applet
Two user chess game  Write a program for a two user chess game(Users must be on different systems)? please send me this source code to my mail id with step by step explanation
Sum of integers
Sum of integers  A Java program that reads an integer value from the user and displays i) the sum of all even integers between 1 and the input... value both inclusive Example: User enters 7. Sum of even integers = 2+4+6 = 12 Sum
Swapping of two numbers in java
Swapping of two numbers in java In this example we are going to describe swapping of two numbers in java  without using the third number in java. We... values from the command prompt. The swapping of two numbers is based on simple
print the sum of even number from 1 to 100
print the sum of even number from 1 to 100  how to print the sum of even number from 1 to 100 using for loops? Thanks
How To Read Integer From Command Line In Java
to take integer value from the command line. In this example I have created...How To Read Integer From Command Line In Java In this section we will discuss...); System.out.println("Addition Of Two Numbers = "+sum
Creating Canvas Form Example
Creating Canvas Form Example       This example shows that how to use the Canvas Class in a Form. In this example we take two field in which integer number passed from the form
pie chart flex and sum from hql request
pie chart flex and sum from hql request  hi, i work with flex... d.intituleDeleg,SUM(s.usagePedag ),ROUND((((SUM(s.usagePedag ))/(SUM(s.ordidispo)))*100),0), SUM(s.ordidispo) from Statistiqueordinateur s,Delegation d,Etablissement e
Example of Average, Sum, Min and Max functions in MySQL
Example of Average, Sum, Min and Max functions in MySQL  Hi, How..., Here is few example of aggregate functions in MySQL: mysql> select * from... | +------------------+ 1 row in set (0.00 sec) mysql> select sum(email_count) from email
sum
sum  a program to find the sum of the alternative diagit of it ex- no=123456 sum=1+3+5=9
search in Two Tables to Find data and view by jsp
search in Two Tables to Find data and view by jsp  hi i want search in Two Tables to Find data and view by jsp <%@page import... (create two table the first table: the bills for user the admin insert
to read number from user
to read number from user  1)print the positive equivalent of the number 2) check if the no is integer or not 3) find the square root of the number 4) find the cube of the number
Find sum of the squares of Array elements
Find sum of the squares of Array elements In this section, you will learn how to compute the sum of the squares of the array elements. For this, we have allowed the user to enter 5 numbers, to be stored into the array. Then we have
user registration example
user registration example  hello roseindia i'm searching for a user registration application/example using struts can you pls help me
Change the user input to integer
Change the user input to integer   ... an integer value after the compilation of a program and force the JVM to ask... is in integer but it will be interpreted as a String so, we have to change the string
Calculate sum and Average in java
. Description:- In this example we are calculating sum and average of n numbers. The given code accepts the numbers from the user using BufferedReader class. Then using...Calculate sum and Average in java  How to calculate sum and average
Calculator program in Java
or divide two integer numbers that are input by system. In the given example a class "calculator" is used. System.in takes the input from the system/user at run... into integers. If the user enters a "+" operator it will add the two integer numbers
To find first two maximum numbers in an array
To find first two maximum numbers in an array  Java program to find first two maximum numbers in an array,using single loop without sorting array
How to store two integer value in a separate file and retrieve those values
How to store two integer value in a separate file and retrieve those values  I need to save two values so i can use those values later i came up with idea of saving those values in a separate file and updating values in file
Find L.C.M. of two numbers in Java
Find L.C.M. of two numbers in Java Program In this section, you will learn how to find LCM(Least Common Element) of two integers.The least common multiple is the smallest positive integer that is a multiple of both the numbers. Here we
Java Sum of Digits
Java Sum of Digits In this Java Tutorial section, you will learn how to find the sum of multidigit number. For this purpose, we have allowed the user to enter multidigit number. User can enter any digit number but cannot exceed to 9 digit
Find User Home Directory
Find User Home Directory        In this example we are find user home directory. We... information.ADS_TO_REPLACE_1 The method used into this example
Find a missing element from array
Find a missing element from array We have two arrays A and B where B consists... the array B. From these two arrays, we have to find the missing element from the second array i.e from B. For this, we have calculated the sum of elements from both
Calculating Sum of two Multidim
Sum of Multidimensional Arrays   ... that will calculate the sum of the matrix. To make this program run we need to declare two multidimensional array of type int. Firstly calculate the length
how to find which user has modified the file
how to find which user has modified the file  how to find which user has modified the file
Spring MVC User Registration example
Spring MVC User Registration example  hi, I am unable to find springMVCUserRegistration example full code can u send me full code of this example   Please visit the following link: Spring MVC USer Registration
ModuleNotFoundError: No module named 'find-ida-user-dir'
ModuleNotFoundError: No module named 'find-ida-user-dir'  Hi, My... named 'find-ida-user-dir' How to remove the ModuleNotFoundError: No module named 'find-ida-user-dir' error? Thanks   Hi, In your

Ads