Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner; //import scanner to be able to read data from user.
- public class program1
- {
- public static void main(String[] args)
- {
- //Basic calculator
- double num1, num2, sum;
- Scanner user_input = new Scanner(System.in);
- System.out.print("Number 1: ");
- num1 = user_input.nextDouble(); //nextDouble() scans the input as a double. A number with decimals.
- System.out.print("Number 2: ");
- num2 = user_input.nextDouble();
- sum = num1 + num2;
- System.out.printf("Sum: ", sum); //println() Not capable of printing string and double in the same parameter so i used printf()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement