Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- // combining 25C and 27B to make a checker
- public class Main {
- public static void main(String[] args) {
- Main call25A = new Main();
- Scanner sc = new Scanner(System.in);
- String txt1 = "";
- String txt2 = "";
- double num1 = 0;
- double num2 = 0;
- String userInput;
- boolean isValid = true; // isang false lang ang kelangan
- System.out.print("Enter txt1 >> ");
- userInput = sc.nextLine();
- if (userInput == null || userInput.length() == 0) {
- isValid = false;
- } else {
- txt1 = userInput;
- }
- System.out.print("Enter txt2 >> ");
- userInput = sc.nextLine();
- if (userInput == null || userInput.length() == 0) {
- isValid = false;
- } else {
- txt2 = userInput;
- }
- System.out.print("Enter num1 >> ");
- userInput = sc.nextLine();
- if (userInput == null || userInput.length() == 0
- || call25A.isNumeric(userInput) == false) {
- isValid = false;
- } else {
- num1 = Double.parseDouble(userInput);
- }
- System.out.print("Enter num2 >> ");
- userInput = sc.nextLine();
- if (userInput == null || userInput.length() == 0
- || call25A.isNumeric(userInput) == false) {
- isValid = false;
- } else {
- num2 = Double.parseDouble(userInput);
- }
- if (isValid) {
- System.out.println("txt1: " + txt1);
- System.out.println("txt2: " + txt2);
- System.out.println("num1: " + num1);
- System.out.println("num2: " + num2);
- } else {
- System.out.println("One of the user input is invalid");
- }
- }
- public 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