Home Answers Viewqa Java-Beginners write a program which asks the user for two int values and calculates their sum.

 
 


Simon Toma
write a program which asks the user for two int values and calculates their sum.
2 Answer(s)      a year and 11 months ago
Posted in : Java Beginners

The title says it all, an example is (1,2) > 3

View Answers

June 2, 2011 at 12:29 PM


import java.util.*;

public class Calculate {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("Num1: ");
        int num1 = input.nextInt();
        System.out.print("Num2: ");
        int num2 = input.nextInt();
        if (num1 > 0 && num2 > 0) {
            int sum = num1 + num2;
            System.out.println("Sum= " + sum);
        }
            else {
            System.out.println("Invalid Numbers");
            System.out.println("End of program");
        }
    }
}

April 15, 2013 at 2:01 AM


with java

Write a program to get student grade for 3 different subjects, and display the CGPA for them.

Write a program to read 8 integer numbers from user, put them into 2 matrix A and B(2 by 2), and multiply the matrix and display the result.









Related Pages:
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
write following program
on thread synchronization with examples Q4 WAP that asks the user to input...-cycle? Q10 WAP that asks the user to input 2 string. If the strings are same...write following program  Q1 What is the difference between single
Programming: Initials 1
________________________________________ Write a program that asks for names and displays the initials. Ask the user for their first name. Save it in a string variable. Ask the user for their last...() method to convert them to upper case. Display the initials to the user
help to write a program for biology to know if two person are related or not
point and end point , i need only help to write the two method which sum rows...help to write a program for biology to know if two person are related... in 2d array but i have wrote program to sum the ones each rows and compared
how to write this program
how to write this program  Write a program in java which calculates... or numerical grade. You will be submitting TWO versions of this program. Write one...?¢s GPA. This program should take a studentââ?¬â?¢s First Name, Last Name a GPA
write a java program for pagination which will be configured by end user
write a java program for pagination which will be configured by end user  write a java program for pagination which will be configured by end user
sum of all values in a column of jtable
sum of all values in a column of jtable  hey everyone, is there a code to display the sum of all values in a column of a jtable namely CARTtbl... or deleted.   Here is an example of jtable that sums up the values of two
write a java program for pagination which will be configured by end user
write a java program for pagination which will be configured by end user  write a java program for pagination which will be configured by end user  
How to compare two tables, and insert values which r not in one table to another table?
How to compare two tables, and insert values which r not in one table to another table?  Hi I need to compare two tables MainTable and OUTTable... is selecting all the values which r not in maintable...but not inserting
Sum of positive and negative numbers
Sum of positive and negative numbers  Hi if someone could help that would be great Write a program to read in 10 integer values and output the sum of all the positive integers and the sum of all the negative integers.  
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
Calculating Sum of two Multidim
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... Sum of Multidimensional Arrays   
Dynamically display values in dropdown box and then show the selected values as selected by the user which is already stored in the DB
as selected by the user which is already stored in the DB   Hello, This is for Updating. I had two SQL queries one for only selected values the user has choosen before and the second SQL query to show all the values. Iwas
Write a C language program to read two matrices and multiply them?
Write a C language program to read two matrices and multiply them?  Write a C language program to read two matrices and multiply them?   ...;stdio.h> #include <conio.h> int main() { int m, n, p, q, c, d, k, sum
Sum of two Matrix
to this. In this program we are going to calculate the sum of two matrix. To make this program... Sum of  two Matrix       In this section, we are going to calculate the sum of two matrix
Calculate the Sum of three Numbers
will be added in the Addition method which we have declared in our program. Now... which will return the integer value and the value will be displayed to the user... Calculate the Sum of Three Numbers   
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 first n numbers
Sum of first n numbers  i want a simple java program which will show the sum of first n numbers....   import java.util.*; public class...=input.nextInt(); long sum=0; for(int i=1;i<=n;i++){ sum+=i
Change the user input to integer
will create a object of a Rectangle class. Now we ask the user to input two values.... In the first class we have used two methods, show(int x, int y) and calculate(). First...() calculates the area of a rectangle. In the second class which is also our main
Calculate sum and Average in java
(); int num = Integer.parseInt(data); int sum = 0; float avg = 0.0f; for (int i = 1; i <= num; i++) { sum = sum + i...Calculate sum and Average in java  How to calculate sum and average
Java radio buttons and button groups two values
Java radio buttons and button groups two values  hi i have a problem... is clicked depending on which button was clicked male or female be sent... java.sql.Statement; /** * * @author User */ public class RegistrationUIMenu1 extends
Java radio buttons and button groups two values
Java radio buttons and button groups two values  hi i have a problem... is clicked depending on which button was clicked male or female be sent... java.sql.Statement; /** * * @author User */ public class RegistrationUIMenu1 extends
Writing and testing method of addition of two numbers
a method named sum() which takes two int parameters and return addition of these two... method which takes two int parameters to add them and return it . Save and compile this file. public class Calculator{   int sum(int
Dialog I/O: Kilometers to Miles
Java NotesDialog I/O: Kilometers to Miles This basic program asks the user for a number of miles and converts it to kilometers. It uses JOptionPane... dialog boxes from program Source code 1 2 3 4 5
Write Keys and Values to the Properties file in Java
how to write keys and values in the properties files through the Java program. The program for writing keys and values to the properties file has been mentioned... Write Keys and Values to the Properties file in Java
sum
sum  a program to find the sum of the alternative diagit of it ex- no=123456 sum=1+3+5=9
Java Sum of Digits
. Following code calculates the sum of digits: while (n > 0) { int p... the sum of multidigit number. For this purpose, we have allowed the user to enter... static void main(String args[]) { int sum = 0; System.out.println("Enter
How to prompt user
. Pls help to write program as below :- a)to prompt user to input 2 integers... sum=0; System.out.println("Enter number1: "); int digit1... of Digit 1 and Digit 2, indicating which is 1st & which is 2nd number. c
accept integer from user
message needs to be displayed if user entered input which is not in this range... parameter that represents the input values in the form of int[] as shown below...accept integer from user  Write an Java application that accepts 100
write a program to create a user defined
write a program to create a user defined   plz send me code   Hi Friend, Please specify what do you want to create? Thanks
int Array
have declared an array of type int then the array will take only the int values...; <tr><td> <% int array[] = {0, 2, 4, 8, 16}, sum = 0; for (int i = 0; i < array.length;i++){ sum=sum
sum
: "); int n=input.nextInt(); int s=1,sum=1; System.out.print("The series : 1+"); for(int i=2;i<=n;i++){ s=(s*10)+i; sum=sum+s; if(i==n){ System.out.print(s
Add Two Numbers in Java
into integer type. Now you can add these values into a sum variable and print... of two numbers! Sum: 32... Add Two Numbers in Java     
PLEASE Help me write a Java program which will store, manipulate, and print student registration information.
PLEASE Help me write a Java program which will store, manipulate, and print..., ADDRESS AND ADMISSIONS CLASS PLEASE HELP!!! Write a Java program which..., and Date, where: (a) Name is a user defined class comprising of at minimum first
Write a program in java...
Write a program in java...  Hi, friends Please, can you help me? Q1: Write a program in java to simulate a calculator. Your program should take two... as a user wishes. Print the result up to two places of decimal. Q2: Ask the user
write program - Java Beginners
write program  write a java program that will read the values... main(String[] args) { int array[][] = {{5,6,7},{4,8,9}}; int array1[][] = {{6,4},{5,7},{1,1}}; int array2[][] = new int[3][3]; int x
write program have product - using loops
write program have product - using loops  Write a program...(list3); double sum=0; for(int i=0;i<list3.size();i++){ sum... the highest price and the average price. A product has three pieces of data: id (int
A program which converts feet and inches to centimeters.
Java: Exercise - InchesToCm Write a program which converts feet and inches to centimeters. In this application we will write code for converting feet... When you run the example it will show the Swing GUI where user can perform
C Addition of two matrices
C Addition of two matrices In this section, we are going to calculate the sum... to declare two dimensional array of integer type. Here, we prompt  the user to input values for two matrices. To make the matrix of 2 X 2, we are using 
two dimensional - Java Beginners
two dimensional  write a program to create a 3*3 array and print...; int sum=0; int[][] matrix; Scanner input = new...++) { for (int j = 0; j < cols; j++) { sum+=matrix[i][j
Write a program to list all even numbers between two numbers
Write a program to list all even numbers between two numbers... Numbers Example in Java: Here you will learn to write a program for listing out all the even numbers between two numbers. For this first create a class named
Two Dimensional Array Program
Two Dimensional Array Program Using Nested for loop...; program . In this session we will teach how to use of a two dimensional array. First of all we will define a class "Matrix". In this program we
Ajax Multiply Two Values
to multiply two values and display the result on the page. This program calls the method 'callmultiply()' for the multiplying  the values entered by user... Ajax Multiplication Program      
sum and average of grades
sum and average of grades  how to print a program which is sum and average of Korean (90), English(85), Mathematics(78), Biology(65), Chemistry(83
Swapping of two numbers
program to calculate swap of two numbers. Swapping is used where  you want to interchange the values. This program will help you to increase your programming ability. In this program we will see how we can swap two numbers. We can do
Addition of two Number in Class
the sum of any two number. Java is a object oriented  programming language... for the efficient read of charactor values. As in this program we are going to insert... Addition of two Numbers in Class   
jaVA INT
jaVA INT  Read a text file and precede the line with the line number and write it to another new text file. For example if you create a file Source.txt which has the following contents: Hello there I am supposed to have line
Java Program - Java Beginners
Java Program  Write a java program to find out the sum of a given number by the user?  Hi Friend, Try the following code: import... num2=input.nextInt(); int sum=num1+num2; System.out.println("Sum of two numbers
Write the Keys and Values of the Properties files in Java
Write the Keys and Values of the Properties files in Java.... It takes the two values of the string types like: key and val. The key... will learn how to add the keys and it's values of the properties files in Java. You
sum of fibonacci series
sum of fibonacci series  Write a Java program to print Fibonacci series upto n and find their sum also. 0+1+1+2+3+5+8+13+21ââ?¬Â¦Ã¢â?¬Â¦Ã¢â?¬Â¦Ã¢â?¬Â¦=sum   Hi, Please see the thread Fibonacci program. Thanks

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.