Using java I need to write a program that gives separate out
Using java,
I need to write a program that gives separate output values by using the formula x+y*4%z
I NEED TO GET OUTPUT VALUES OF 13 14 AND 2 without changing the inital variables of x = 9.8 ,y=4.3 , z = 3.2 and only using the formula x+y*4%z
For example I got the output 13 by doing the example below;
double x = 9.8;
double y = 4.3;
double z = 3.2;
int result;
// formula -> x+y*4%z
result = ((int)x+(int)y)*(4 % (int)z); //goal is to get output of 13
System.out.println(result);
Solution
Hi, Please find my code.
public class test {
public static void main(String[] args) {
double x = 9.8;
double y = 4.3;
double z = 3.2;
int result;
// formula -> x+y*4%z
result = ((int)x+(int)y)*(4 % (int)z); //goal is to get output of 13
System.out.println(result);
result = ((int)(x+y))*(4 % (int)z); //goal is to get output of 14
System.out.println(result);
result = (((int)(x+y)*4) % (int)z); //goal is to get output of 2
System.out.println(result);
}
}
/*
Output:
13
14
2
*/

