JAVA Basic Programs -- Sum of Two Numbers
Sum of two numbers by receiving value from keyboard In this program we use two variables which receive value from the keyboard and add those values and sum of these numbers are stored in the third variable. In this example we are using Scanner, Scanner is a class in java.util package used for obtaining the input of the primitive types like int, double etc. and strings. It is one of the ways to read input in a Java program. Syntax for scanner... Declare the object and initialize with predefined standard input object Scanner sc = new Scanner(System.in); String input String name = sc.nextLine(); Character input char gender = sc.next().charAt(0); Numerical data input byte, short and float can be read using similar-named functions. int age = sc.nextInt(); long mobileNo = sc.nextLong(); double cgpa = sc.nextDouble(); Xample: File_name: Addition .java For Compiling: javac Addition.java For Execution: java ...