Java program to add two numbers
Simple Program to Add two numbers in Java
//A Simple Program to Add Two Numbers in Java Program.
class AddTwoNumbers //Class Declaration
{
public static void main(String args[]) //Main Function
{
int x, y, z; // Variable Declaration
x = 10; //Assigning 10 to the variable x.
y = 20; //Assigning 20 to the variable y.
z = x + y; //Expression to Add two variables x, y and save the result to z
System.out.println("Sum of x and y = "+z); //This line output the value of z on the Screen
}
}
Output:
Sum of x and y =30
y = 20; //Assigning 10 to the variable y.
ReplyDeletePlace of Above Line
y = 20; //Assigning 20 to the variable y
y = 20; //Assigning 20 to the variable y
ReplyDeleteplace of above line
Thanks and updated..
Deletevery good, learn more...............
ReplyDeletethanks, learn much more
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteI AM FROM ANONYMOUS NOOB CODES
ReplyDeletebut i want take two numbers by user,
ReplyDeletehow to take numbers by user and then calculate it's sum
please tell me sir
thanks.
http://www.javatutorialprograms.com/2013/01/java-program-to-add-two-numbers.html
Deleteimport java.io.*;
Deleteclass sid
{
public static void main(String [] args)throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter two no.");
int x=Integer.parseInt(br.readLine());
int y=Integer.parseInt(br.readLine());
int z=x*y;
int a=x+y;
System.out.println("Siddhant"+z+a);
}
}
//Sorry cant explain how it is but this is is try it
i think it need scanner
Deleteimport java.util.Scanner;
Deletepublic class Addition {
public static void main(String[] args) {
// TODO Auto-generated method stub
int a,b,c;
System.out.println("Enter the two numbers here");
Scanner me = new Scanner(System.in);
a= me.nextInt();
b=me.nextInt();
c=a+b;
System.out.println("Addition of two values= " +c);
}
}
[this one is simpler and easy]
Post is good for absolute noobs. Check this out : Short article on how to learn java programming
ReplyDeletePost is good for absolute noobs. Check this out : Short article on how to learn java programming Java programming tutorial
ReplyDeleteInstead of buffer readers u can also take scanner class.
ReplyDeleteimport java.util.Scanner;
ReplyDeleteclass AddNumbers
{
public static void main(String args[])
{
int x, y, z;
System.out.println("Enter two integers to calculate their sum ");
Scanner in = new Scanner(System.in);
x = in.nextInt();
y = in.nextInt();
z = x + y;
System.out.println("Sum of entered integers = "+z);
}
}
im running this on Mac im getting 11 errors
Deletethank
ReplyDeletePost is good..
ReplyDeleteHow about printing like this :
int x=10,y=20;
System.out.println("sum : "+(x+y));
See this as well : Best way to learn java programming
So helpful. Thanks for sharing.
ReplyDeleteIELTS classes in Kuwait
how short datatype use in addition method
ReplyDeletehow short datatype use in addition method
ReplyDeletegreat work
ReplyDeletesir ,,,can u tell me how to run java program using cmd
ReplyDeletefirst
Deletejavac class name.java
then
java class name
This comment has been removed by the author.
Deletekindly visit the link: http://java191.blogspot.com.ng/2017/02/how-to-compile-and-execute-java-program.html
Deleteimport java.util.Scanner;
ReplyDeleteclass AddNumbers
{
public static void main(String args[])
{
int x, y, z;
System.out.println("Enter two integers to calculate their sum ");
Scanner in = new Scanner(System.in);
x = in.nextInt();
y = in.nextInt();
z = x + y;
System.out.println("Sum of entered integers = "+z);
}
}
hi, im running this same code on mac and I am getting 11 errors
Deleteif i want to declare variables with in class then how to write a program for that
ReplyDeleteYou can just add public static int x, y, z; in the class to use the variables. Java program to add two numbers
Deleteif i want to declare variables with in class then how to write a program for that
ReplyDeleteCheck here with the steps : Java program to add two numbers
ReplyDeleteWrite A Programs
ReplyDeleteGood Explanation.....
Helpful For Beginners.
in addition to the program. We can modify the program in such a way that the user input two numbers then it displays the sum of the two numbers in a message dialog box. You can check out the program and detailed explanation of the code through the following link: http://java191.blogspot.com.ng/2017/02/java-addition-program-that-uses.html
ReplyDeleteGood and nice information, thanks for sharing your views and ideas...
ReplyDeleteWeb Designing Training in chennai | PHP Training in chennai
Great post aboutjava programs
ReplyDeletethanks
Data type not mention....It generate error
ReplyDeleteIn mahrien fariha's method
ReplyDeletewithout using scanner and we will not declare the variables in the program it can possiable
ReplyDeletePlease tell about Return type with example
ReplyDeleteSince all execution happens on the program, Javascript is in charge of the majority of the intelligence on a website page. code online easily
ReplyDelete