Simplify the following piece of code: (java)
if (a>b)
x = a + b;
if (a>0)
x = a + b;
We can simplify these statements as :
if a>b OR a>0 then x=a+b
import java.util.Scanner;
public class simplify {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter value of a");
float a=scanner.nextFloat();
float x=0;
System.out.println("Enter value of b");
float b=scanner.nextFloat();
if((a>b)||(a>0)){
x=a+b;
}
System.out.println("Value of x= "+x);
}
}
Get Answers For Free
Most questions answered within 1 hours.