In this program we are getting 2 Integer values from user and adding it then printing that into console.
public class DataFromUser { //Default Class
public static void main(String[] args) { //Main Function
Scanner in = new Scanner(System.in); //defining In to scan
System.out.println("Enter Data 1 and Data 2 to Add");
//getting datas from use
int a = in.nextInt();
int b = in.nextInt();
//Calculating addition
int c= a+b;
//printing result
System.out.println("The Sum of entered numbers is "+c);
}
}
Program:
import java.util.Scanner; //Library to use scanning user datapublic class DataFromUser { //Default Class
public static void main(String[] args) { //Main Function
Scanner in = new Scanner(System.in); //defining In to scan
System.out.println("Enter Data 1 and Data 2 to Add");
//getting datas from use
int a = in.nextInt();
int b = in.nextInt();
//Calculating addition
int c= a+b;
//printing result
System.out.println("The Sum of entered numbers is "+c);
}
}
Output:
Enter Data 1 and Data 2 to Add
4
8
The Sum of entered numbers is 12
0 comments:
Post a Comment