Implement the program using for-loop

Assignment Help JAVA Programming
Reference no: EM131565649

QUESTION 1
1. Complete the following method, which compares two parameters and returns -1, 0, or 1 if the first parameter is less than, equal to, or greater than the second parameter. Note answers are case sensitive.
public int compare(int a, int b) {
result; // declare variable of appropriate type. The variable will get its value then be returned.
if (a<b} {
= -1; // assignment -1 to which variable?
} else (a b) {// when the two parameters have same value, assign 0 to variable to be returned
= 0;
} else { // a must be great than b in this case
result = 1;
}
result; //one of the branching keywords.
}

QUESTION 2
1. The following switch statement decides the value of g based on the value of s (whose types have been declared elsewhere).
switch (s) {
case 9:
g="A";
;
case 8:
="B";
;
default:
g ="F";
}

Then complete the following code that is equivalent to the above switch statement.
if (s 9) {
g = "";
} else (s 8) {
g = "";
} {
g="F";
}

QUESTION 3
1. Indicate the values printed when the following code executes:
for (int i=1, j=5; i<=j; i++, j--) {
System.out.printf("%d %d %dn", i, j, i+j);
}

QUESTION 4
1. The following flowchart depicts a part of program that calculates 20 years of the annual value of an investment account with an initial balance of v, an annual additional investment a deposited into the account, and an annual rate of return r randomly drawn from a uniform distribution. Implement the program using for-loop.

Here is partially finished code. Fill in the blanks to complete it.
double v=1000, a=600; //initial value $1000; invest $600 at the end of each year
double r; // variable for storing annual rate of return
for (int = ; 20; i) {
r = -3 + 15*Math.random() ; //r is between -3 to 18%
v = v*(1+r/100)+a;
System.out.printf("%5 %5.2 %,10.0", i, r, v); // supply conversion characters
}

QUESTION 5
1. After the following code finishes executing, the value of the result variable is , the value of the i variable is . (Note: use numeric values for your answer)
int i=4, result=1;
while(i>1) {
result *= i;
i--;
}

Reference no: EM131565649

Questions Cloud

Write code that uses the input string stream : Write code that uses the input string stream inSS to read input data from string userInput, and updates variables userMonth, userDate, and userYear.
Define respect to security functions : There are many critics of privatization, with respect to security functions. However, airport security screening has come under intense scrutiny in recent years
What cultural influences on financial reporting in america : Lowly Coffee, Ltd. (a Vietnamese company) is a client of AJJ. What are the cultural influences on financial reporting in America
Discuss about the fleet safety program : List and explain the significance of the three main areas of concentration in motor fleet security functions.
Implement the program using for-loop : Implement the program using for-loop - Complete the method, which compares two parameters and returns
Explain at least two reasons how the death penalty : Identify and explain at least two reasons how the death penalty DOES deter and supports/contributes to public safety
What are the indicators for using an anova : What are the indicators for using an ANOVA? Create a research scenario in which it would be correct to use an ANOVA, including the research question.
Write a summary of the main parts of the paper : Introduction: Objectives of the thesis, referring to the guidelines Presentation of the approved topic. Summary of the main parts of the paper.
Compute the cost of goods sold : Compute the cost of goods sold, cost of ending merchandise inventory, and gross profit using the FIFO inventory costing method

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd