Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mrb5week4;
- import java.util.Scanner;
- public class Day19B {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- double num1 = 0;
- double num2 = 0;
- double numTotal = 0;
- String op = "+";
- String userInput = "";
- System.out.print("num1: ");
- userInput = sc.nextLine();
- if (isNumeric(userInput)) {
- num1 = Double.parseDouble(userInput);
- }
- System.out.print("operator: ");
- op = sc.nextLine();
- System.out.print("num2: ");
- userInput = sc.nextLine();
- if (isNumeric(userInput)) {
- num2 = Double.parseDouble(userInput);
- }
- System.out.println(num1 + " " + op + " " + num2);
- }
- public static boolean isNumeric(String strNum) {
- if (strNum == null) {
- return false;
- }
- try {
- double d = Double.parseDouble(strNum);
- } catch (NumberFormatException nfe) {
- return false;
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment