Write a Java program to print the result of the following operations.
Your program should contain 4 methods (for each of given data sets). Yes, methods here are not structurally necessary, this requirement is only for you to get practice writing methods.
Test Data:
a. -8 + 4.0 * 6
b. (11+9) % 9
c. 20 + (-3)*3.0 / 8
d. 5 + 14 / 3 * 2 - 7 % 3
Your program:
class Test
{
public static void main (String[] args)
{
method1();
method2();
method3();
method4();
}
public static void method1()
{
System.out.println(-8 + 4.0 *
6);
}
public static void method2()
{
System.out.println((11+9) %
9);
}
public static void method3()
{
System.out.println(20 + (-3)*3.0 /
8);
}
public static void method4()
{
System.out.println(5 + 14 / 3 * 2 -
7 % 3);
}
}
Output:
16.0 2 18.875 12
Do ask if any doubt. Please up-vote.
Get Answers For Free
Most questions answered within 1 hours.