Question

In: Computer Science

In each part below, a task is described. Your job is to write one or more...

In each part below, a task is described. Your job is to write one or more JAVA statements which will accomplish this task. Assume that all variables have data type int. If you need other variables you may declare them and use them.

a. 6 pts Assume that variables x, y, and z have values. Print all the values from x to y that are evenly divisible by z. For example, if x is 6, y is 18, and z is 4, it would print 8 12 16

b. 6 pts. Given a year number, year, calculate and print how many centuries (100 years), decades (10 years), and years have passed since 0 CE. For example, for year = 2021, you would print “Year 2021: 20 centuries, 2 decade(s), 1 year(s)”.

Solutions

Expert Solution

// Part A

int x = 6, y = 18, z = 4;
for (int num = x; num <= y; num++) {
    if (num % z == 0) System.out.print(num + " ");
}

==========================================================

// Part B
int year = 2021;

int centuries = year / 100;
int decades = (year % 100) / 10;
int years = year % 10;

System.out.println("Year " + year + ": " + centuries + " centuries, " + decades + " decade(s), " + years + " year(s).");

===============================================================


Related Solutions

Please explain in 300 words or more the task below: Your task involves an analysis of...
Please explain in 300 words or more the task below: Your task involves an analysis of general economic conditions or systematic risk, i.e., the risk that affects all industries and companies, in the U.S. macroeconomy. Your goal is to determine in percentage terms an optimal allocation of $1,000,000 among the following three asset classes: U.S. equities, U.S. Treasury bonds, and cash. Submit your analysis of U.S. Treasury bonds. Keep in mind that the purpose of your analysis is to determine...
A) Using the scenario described by “Each store employs one or more employees; each employee is...
A) Using the scenario described by “Each store employs one or more employees; each employee is employed by one store”, work the following problems: 1. Identify each entity. 2. Identify each relationship type. Justify your answer. 3. Create the basic Crow's Foot ERD using Visio. B) Using the scenario described by “A job assignment can be assigned to more than one employee at a time; each employee can have only one job assignment”, work the following problems: 1. Identify each...
For each transaction described below, write the name of the account that would be debited and...
For each transaction described below, write the name of the account that would be debited and the name of the account that would be credited when recording the transaction. No dollar amounts or explanations are required. Transaction To Record the Transaction in a Journal Entry, Name the Accounts that you would debit and credit Account to DEBIT Account to CREDIT Company purchased inventory on account Company sold/provided services for cash Company recorded depreciation on equipment for the period Company paid...
For each transaction described below, write the name of the account that would be debited and...
For each transaction described below, write the name of the account that would be debited and the name of the account that would be credited when recording the transaction. Company purchased inventory on account Company sold/provided services for cash Company recorded depreciation on equipment for the period Company paid NEXT YEAR’s insurance premium Company paid vendor for a prior purchase on account Company paid utility bill Company received cash deposit from customer for work to be performed in the future...
Write your plan for the investigation as described below and save it as a Word document.
  Fire Suppression Investigation Plan Write your plan for the investigation as described below and save it as a Word document. Detailed one page summary of your plans, including sketches if necessary. (Note: If you cannot submit your sketches, describe them in words.) Itemized list of materials, with total costs. Stoichiometric calculations of the amount of reactants required to produce enough gas to extinguish the fires. Remember that some gas may be lost prior to its use as a fire...
The preparations of two aqueous solutions are described in the table below. For each solution, write...
The preparations of two aqueous solutions are described in the table below. For each solution, write the chemical formulas of the major species present at equilibrium. You can leave out water itself. Write the chemical formulas of the species that will act as acids in the 'acids' row, the formulas of the species that will act as bases in the 'bases' row, and the formulas of the species that will act as neither acids nor bases in the 'other' row....
Write the null and alternative hypotheses for each situation described below, and indicate whether each test...
Write the null and alternative hypotheses for each situation described below, and indicate whether each test would be left-tailed, right-tailed, or two-tailed. Make sure that you use the correct population parameter. To submit the assignment, you may just type your answers in the text box. (You don't have to worry about typing subscripts or Greek letters on this assignment unless you want to. For example, for , you could type H0: mu = 30.) 1. A cereal manufacturer claims that,...
Instructions: Below is the illustration of approaches to family nursing, your task is to discuss each...
Instructions: Below is the illustration of approaches to family nursing, your task is to discuss each approach in your own perspective/view and relate its significance in working in any given family. Write down your answers in a separate sheet of paper. (see rubrics for scoring) 1. Family as Context 2. Family as Client 3. Family as System 4. Family as Component of Society TASK 2. FAMILY CASE STUDY Instructions: All questions apply to this case study. Your responses should be...
Write a program calls each of the three methods described below and prints out the result...
Write a program calls each of the three methods described below and prints out the result of the two methods which return value reverse- a void method that reverses the elements of the array. Print the array before you call the method and after call the method. getMin- an int method that returns the smallest value in the array Sample output array: 22,34,21,35,12,4,2,3,99,81 array in reverse: 81,99,3,2,4,12,35,21,34,22 the smallest number is 2
Task Create an outline (plan to write your message – sample outline provided below) and an...
Task Create an outline (plan to write your message – sample outline provided below) and an email message based on case details identified below. Situation You work as an assistant office manager for Diamond Clear, a family-run window installation company and a scheduling issue has arisen in the office. You are writing on behalf of Lucia to her brother Scott regarding the situation (includes the problem) and your request (main idea). In your email message you will inform Scott that...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT