Question

Write a Java code to complete the following operations: (1) Define a double variable var1, initialize...

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

Homework Answers

Answer #1

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!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
java Write a single Java statements to accomplish each of the following: a) Displaythevalueoftheseventhelementofcharacterarraych. b) Considering...
java Write a single Java statements to accomplish each of the following: a) Displaythevalueoftheseventhelementofcharacterarraych. b) Considering “Scanner in = new Scanner (System.in);”, input a value into element 5 of one-dimensional double array nums. c) Initialize each of the four elements of the one-dimensional integer array test to 7. d) Declare and create an array called table as a float array that has four rows and three columns. e) Considering the following ArrayList declaration, insert “test” at the fourth position (index...
For Java programming code: Write methods to add and multiply 1) Two integers 2) Two decimals...
For Java programming code: Write methods to add and multiply 1) Two integers 2) Two decimals 3) One integer and one decimal
For the following class Book: 1- Write a default constructor to give default values (title= Intro...
For the following class Book: 1- Write a default constructor to give default values (title= Intro to Programming and price = 20) to the class’s variables. 2 - Write a parameterized constructor to allow the user to initialize the class variables. 3- Write getter & setter for each variable of this class. 4- Then write a main code to create an instance of this class using parameterized constructor, ask user for inputs to initialize the variables of this instance and...
Write the java code that will convert the given Before links to the After links with...
Write the java code that will convert the given Before links to the After links with comments. For example: Before:            +----+----+    +----+----+ list ----> | 1 | +----> | 2 | / |            +----+----+    +----+----+ After:            +----+----+    +----+----+    +----+----+ list ----> | 1 | +----> | 2 | +----> | 3 | / |            +----+----+    +----+----+    +----+----+ Code: (example answer) list.next.next = new ListNode(3, null);   // 2 -> 3 (1) Before:            +----+----+    +----+----+ list ---->...
program in java 1- Write a code to remove continuous repeatitive elements of a Linked List....
program in java 1- Write a code to remove continuous repeatitive elements of a Linked List. Example: Given: -10 -> 3 -> 3 -> 3 -> 5 -> 6 -> 6 -> 3 -> 2 -> 2 -> NULL The answer: -10 -> 3 -> 5 -> 6 -> 3 -> 2 -> NULL
Part 1 Given the following code: public class MyClass { private double score; private String studentID;...
Part 1 Given the following code: public class MyClass { private double score; private String studentID; //code of the class ..... } //end of MyClass Code a default constructor and an overloaded constructor of MyClass that will assign values to its two instance fields: Please write in JAVA Part 2 Continue from question about, code an mutator of instance field called studentID:
(in java) a. Include a good comment when you write the method described below: Write a...
(in java) a. Include a good comment when you write the method described below: Write a method factorial which receives a positive integer n and calculates n! (n factorial), defined as follows: n!=1*2*…*(n-1)*n. For example, 5! = 1*2*3*4*5 = 120. The method should return this value to the calling program. b. Write a driver program (main method) which will read an integer from the console, and pass it to the method to calculate its factorial. The main method then prints...
1. Given a matrix variable "mat", write code using for loops, if statements, etc. that will...
1. Given a matrix variable "mat", write code using for loops, if statements, etc. that will accomplish the same as the following: matsum = sum(mat') Please make sure to store the result in "matsum" and dont use sum. This is what I have so far but it keeps telling me is wrong.... % mat has been initialized for you: mat = randi([-100,100],randi([15,20]),randi([15,20])); % write your statements that accomplish the code above: [r c]=size(mat); for i=1:c matsum=0; for j=1:r matsum=matsum+mat(j,i); end...
Design a class with the following requirements: 1- give the class a name from your choice....
Design a class with the following requirements: 1- give the class a name from your choice. 2- write some code that creates three instance variables, choose a name and type for each one of them. (must have two private and one public variables) 3- Initialize the variables using two different constructors. 4- Use mutator and accessor methods (set and get) for the private data members. 5- Display the value of each member variable using a method. 6- In the main,...
1) Write a java programming using a while loop where you will add numbers and when...
1) Write a java programming using a while loop where you will add numbers and when you press number 0 it will add all your numbers and display the results. Use Scanner object. Steps: 1) Declare variables integer called sum which is equal to zero   2) Declare Scanner object   3) Declare while condition where is true   4) Inside of that condition prompt the user to enter the numbers   5) Declare variable integer called number and input the number statement   6)...