How do I modify the code so that it only shows "It is True to say that first value 2.0 is equal to Second value2.0" if the values are correct and exclude " It is False to say that first value 2.0 is larger to Second value 2.0" in the output. INPUT: package R; import java.util.Scanner; public class R { public static void main(String[] args) { Scanner sc = new Scanner(System.in); //System.in is a standard input stream. double firstNum, secondNum; System.out.print("enter first value: "); firstNum = sc.nextDouble(); System.out.print("enter second value: "); secondNum = sc.nextDouble(); if (firstNum > secondNum) System.out.println("It is True to say that first value " + firstNum + " is larger to Second value" + secondNum); else System.out.println("It is False to say that first value " + firstNum + " is larger to Second value " + secondNum); if (firstNum == secondNum) System.out.println("It is True to say that first value " + firstNum + " is equal to Second value" + secondNum); } } OUTPUT: enter first value: 2 enter second value: 2 It is False to say that first value 2.0 is larger to Second value 2.0 It is True to say that first value 2.0 is equal to Second value2.0 Process finished with exit code 0
Q. How do I modify the code so that it only shows "It is True to say that first value 2.0 is equal to Second value2.0" if the values are correct and exclude " It is False to say that first value 2.0 is larger to Second value 2.0" in the output.
INPUT:
package R;
import java.util.Scanner;
public class R {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in); //System.in is a standard input stream.
double firstNum, secondNum;
System.out.print("enter first value: ");
firstNum = sc.nextDouble();
System.out.print("enter second value: ");
secondNum = sc.nextDouble();
if (firstNum > secondNum)
System.out.println("It is True to say that first value " + firstNum + " is larger to Second value" + secondNum);
else
System.out.println("It is False to say that first value " + firstNum + " is larger to Second value " + secondNum);
if (firstNum == secondNum)
System.out.println("It is True to say that first value " + firstNum + " is equal to Second value" + secondNum);
}
}
OUTPUT:
enter first value: 2
enter second value: 2
It is False to say that first value 2.0 is larger to Second value 2.0
It is True to say that first value 2.0 is equal to Second value2.0
Process finished with exit code 0
Step by step
Solved in 2 steps with 2 images