1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Serjik [45]
3 years ago
7

Iven the code fragment below with nested if statements, rewrite the code to combine all the tests into one if statement with mul

tiple conditionals. Paste (or type) the rewritten code into your answers document.
int feb = 28;

if ((year % 4) == 0) // assume that year is an integer with a valid year value

{

if ((year % 100) != 0)

{

System.out.println("This is a leap year");

feb = 29;

}

}

If the value of year is 2020, what will the value of feb be after this code runs?
Computers and Technology
2 answers:
Georgia [21]3 years ago
8 0

Answer:

See Explanation Below

Explanation:

The new code segment is

int feb = 28;

if ((year % 4) == 0 && (year % 100) != 0) // assume that year is an integer with a valid year value

{

System.out.println("This is a leap year");

feb = 29;

}

Assume year = 2020, the assigned value of feb is 29;

Reason below;

At line 2 of the new code segment, two conditions are tested both of which must be satisfied.

1. year % 4 == 0

2020 % 4 = 0

0 = 0 (True)

2. year % 100 != 0

2020 % 100 != 0

20 != 0 (True)

Since both conditions are true, the value assigned to feb will be 29 and

"This is a leap year" will be printed without the quotes

trasher [3.6K]3 years ago
6 0

Answer:

public class Main {

   public static void main (String [] args) {

       int year = 2016;

       int feb = 28;

       if ((year % 4) == 0 && (year % 100) != 0)

       {

               System.out.println("This is a leap year");

               feb = 29;

       }

   }

}

Explanation:

We can use the and logical operator, &&, to join the nested if statements into one single statement. The and operator will first evaluate the condition year % 4 is equal to zero and then followed with checking if year % 100 is not equal to 100. If only both conditions are met, it will evaluated to true and then go in to the if block to print the message "This is a leap year" and set 29 to variable feb.

You might be interested in
A piano manufacturer employs piano technicians who inspect instruments before they are shipped to customers: a.When inspecting a
77julia77 [94]

Answer:

a.When inspecting an instrument, Technicians apply specific Inspection Tests; more than one Test can be applied for an inspection. Each piano is inspected by at least one technician, and a technician can inspect more than one instrument.

Explanation:

An Inspection test  is a formal approach used to test a system or product such as machines, package, software. This can be done by dimension inspection,  visual inspection, welding inspection, function test, factory acceptance test. Three major factors to be considered in the test plan include:

Test Coverage,

Test Methods, and

Test Responsibilities

There are specific inspection tests that should be applied when inspecting an instrument. A technician can apply more than one test type to assess the authenticity of a product. More than one technician is needed to ascertain the working mehanism of a machine to ensure it has no fault. A technician  can inspect more than one instrument depending on his diversity of specialization.

5 0
3 years ago
Does anyone know about the progressive era?
Umnica [9.8K]

Answer: The Progressive Era was a period of widespread social activism and political reform across the United States that spanned the 1890s to the 1920s.

Explanation:

8 0
4 years ago
Read 2 more answers
You decide to add 3 new hard drives to your computer so that you can increase the amount of storage one it when you install them
Tasya [4]

Answer:

b. Use a Molex to SATA power adapter.

Explanation:

SATA power connector is a 15 pin power connector that is used to connect many computer parts like hard drive, cd drive, SSD, etc.

Molex connector is an old connector that is used as a power connector instead of a SATA connector on the same devices.

But the SATA connector overcomes the Molex connectors as it is easy to use and easy to install and can widely be used in many peripherals.

But even now power supply of the computer contains the SATA power connector as well as some spare Molex connector, which can be used when required.  

There are many Molex to SATA connectors that are easy to use when there is a shortage of SATA power.

So, according to the scenario, the most appropriate answer is option b.

3 0
3 years ago
Write a class named Accumulator containing: An instance variable named sum of type integer. A constructor that accepts an intege
Genrish500 [490]

Answer:

The following are the code in the C++ Programming Language.

//define header file

#include <iostream>

// using namespace

using namespace std;

//define a class

class Accumulator

{

//set private access modifier

private:  

//declare integer type variable

int sum;

//set public access modifier

public:

//define constructor  

Accumulator (int sum)

{

//refer the same class as instance variable

this->sum = sum;

}

//define integer type function

int getSum()

{

//return the value of sum

return sum;

}

//define void type function

void add (int value)

{

//variable sum is increased by the argument value

sum += value;

}

};

Explanation:

<u>The following are the description of the code</u>.

  • Firstly, set the required header file and namespace then, define a class 'Accumulator' and inside the class.
  • Set private access modifier then, declare an integer data type variable 'sum'.
  • Declare a class constructor whose name is the same as the class name 'Accumulator()' and pass integer data type argument 'sum' in its parameter that refers to the same class as instance variable.
  • Define a integer data type function 'getSum()' that return the value of the variable sum.
  • Finally, define a void type function 'add()' and pass the integer data type argument 'value' in its parameter in which the variable sum is increased by the argument value .
4 0
4 years ago
What are the five parts of computer hardware that can be found in most computer systems?
pashok25 [27]

Answer:

processor, primary storage, secondary storage, input devices and output devices

Explanation:

processor, primary storage, secondary storage, input devices and output devices are the five parts of computer hardware that can be found in most computer systems

8 0
3 years ago
Other questions:
  • B. Find Addition of Binary Numbers: 1100112 + 11012
    11·1 answer
  • Question 3 / 5
    9·1 answer
  • A very simple device that connects network components and sends packets of data to all other connected devices is called a _____
    5·1 answer
  • You administer a Microsoft SQL Server database that supports a banking transaction management application. You need to retrieve
    5·1 answer
  • o maintain reasonable key security (mark all that apply): Ensure that someone else always has an extra key. Ensure that no extra
    10·1 answer
  • What are the coordinates of the origin point? (Select the best answer.)
    10·1 answer
  • Please check my answer! (Java)
    6·1 answer
  • What is a computer system?
    9·1 answer
  • What is the iterative procedure of recursive and nonrecursive?
    10·1 answer
  • Slack how to enable direct message to outside workspace
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!