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

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.


April 19, 2017 at 5:31 AM

import java.util.Scanner //Console input rather than JPanes

{

       public static void main(String[] args)
       {
                 Scanner x = new Scanner(System.in);
                 System.out.println("Enter number 1 ");
                 int first = x.nextInt();
                 System.out.println("Enter number 2 ");
                 int second = x.nextInt(); 
                 System.out.println("Enter number 3 ");
                 int third = x.nextInt();
               double GPA = (first + second + third / 3) / 20 ;
                 GPA--; //Equal to GPA = GPA - 1; 
                 System.out.print(GPA);
         }                                                      }

Ads









Related Tutorials/Questions & Answers:
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 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
Advertisements
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  
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
Create a Program that Calculates Input
Create a Program that Calculates Input   Create a program that takes user input and does a calculation with it, then prints the results back for the user. This could include like a sales tax calculator, or a tip calculator
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
Write a program that takes the marks of user as input
Write a program that takes the marks of user as input  Write a program that takes the marks of user as input. If marks are greater then 60... not understand how to write a program like this and thank you
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
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
Python sum dictionary values by key
Python sum dictionary values by key  Hi, In python we can easily... values. We are getting these two dictionaries from two different web services. We want to merge these dictionaries into one and sum the dictionary values by key
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 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
Dynamically display values in dropdown box and then show the selected values as selected by the user which is already stored in the DB
Dynamically display values in dropdown box and then show the selected values as selected by the user which is already stored in the DB  The below..., this is a update screen where user can go and reselect those values..... plz
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 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
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
Sum of two numbers using command line arguments in Java
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? The calculate the sum of two numbers using command line arguments in Java
write a program that Implement an integrated COM client server to add two numbers.by visuall studio 2010
write a program that Implement an integrated COM client server to add two numbers.by visuall studio 2010  write a program that Implement an integrated COM client server to add two numbers.by visuall studio 2010 if someone can do
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
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
write a program  write a program add 2 no.s without use arithmetic,unary operaters in java
Write a program in JAVA which accepts a sentence & displays the longest word in the sentence alongn with it length of the word.
Write a program in JAVA which accepts a sentence & displays the longest word in the sentence alongn with it length of the word.  **A program in JAVA which accepts a sentence & displays the longest word in the sentence along
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 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 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
python merge two dictionaries add values
the values (int values) into the merged dictionary. For example student marks in three...,"chemistry":25,"math":29,"english":34} I want to merge and sum the values...python merge two dictionaries add values  Hi, In Python I have two
A program to find the sum of odd number
A program to find the sum of odd number In this section you will learn how... the console. Now here is the simple example which will help you to find the sum of odd... number"); Scanner sin; int m,n,sum=0; sin=new Scanner(System.in); n
write a java program to find the summation of all the integers entered on command line
write a java program to find the summation of all the integers entered on command line  Hi, write a java program to find the summation of all the integers entered on command line? How to write Java program for summation of all
WRITE A PROGRAM IN JAVA
WRITE A PROGRAM IN JAVA  Write program which accepts five students id,name,age,department,courses, taken and its grade. a. calculate its GPA . display all student information in ascending order
Write a java application program........?
Write a java application program........?  Welcome every One : I have Q in Java? Q : Write a java application program that reads 20 integer numbers input by the user and prints how many numbers > 100 and how many numbers

Ads