Write a Java code to complete the following operations:
(1) Define a double variable var1, initialize it with value 9.99
(2) Given two integer variables var2 and var3, write a statement that gives var3 a value that is 4 more than the value of var2.
(3) Define a double variable var4, initialize it with value 1234.56. Write a statement to change var4 so it will just hold one third (1/3) of the original value
(4) Given four double variables var5, var6, var7, var8. Define the fifth variable var9 which will be initialized with value that is 1/2 * var5 + 1/3 * var6 + 1/4 * var7 + 1/5 * var8
Explanation:
Here is the code which has all the parts of Java code completed and marked with the comments:
Code:
public class Main
{
public static void main(String[] args) {
//Part 1
double var1 = 9.99;
int var2, var3;
//Part 2
var3 = var2 + 4;
//Part 3
var4 = 1234.56;
var4 = (var4/3.0);
double var5, var6, var7, var8;
//Part 4
double var9 = (var5/2.0) + (var6/3.0) + (var7/4.0) +
(var8/5.0);
}
}
PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!
PLEASE COMMENT IF YOU NEED ANY HELP!
Get Answers For Free
Most questions answered within 1 hours.