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
You use_____ to view an XPS file
Katyanochek1 [597]
Firefox
any web browser can open a xps file
4 0
3 years ago
How do networks help protect data? -by preventing access by more than one person at a time -by restricting access to department
Whitepunk [10]

Answer:

because they have to rest

3 0
2 years ago
Read 2 more answers
Accenture is helping a large retailer transform their online sales and services. The Data Analyst audits the client’s customer j
Allushta [10]

Answer:

d. by increasing their customer knowledge and leveraging that information to improve customer experience

Explanation:

Consumers are at the heart of all businesses as they are the ones who our product are targeted. They purchase these goods and the company makes profit. Therefore, it is paramount for businesses to identify their target consumers in other to understand their preference and serve them accordingly. With data analytics, a consumers purchase history, likes and viewed products may be used to improve relationship between consumers and service providers. Once a consumer's preference is anlysed using data, then this is leveraged to improve the kind of service offered to such consumer leasing to better consumer experience.

4 0
2 years ago
What would happen if computers only had input peripherals and a CPU?
lisov135 [29]
Then there would be no way to see the output based off what you input. =)
3 0
2 years ago
How does inertia affect a person who is not wearing a seatbelt during a collision
disa [49]
Inertia would keep them going the same speed as the car was going. therefore, the person not wearing a seatbelt would be sent flying forward, probably ending up dead
8 0
3 years ago
Other questions:
  • A friend has a CD of one of your favorite artists and has offered to let you copy it.
    8·1 answer
  • You have implemented a network where hosts are assigned specific roles, such as for file sharing and printing. Other hosts acces
    7·1 answer
  • Where is the insert function button found in microsoft excel?
    11·1 answer
  • What is the management part of a dashboard?
    10·1 answer
  • Which of the following attacks seeks to introduce erroneous or malicious entries into a server's hostname-to-IP address cache or
    5·1 answer
  • Consider a system that uses a 32-bit unique salt where users have a 4-digit number as a password (e.g. 6813). Eve wants to crack
    8·2 answers
  • Monitors display images by using a grid made up of millions of tiny dots, called ________.
    13·1 answer
  • The nl2br() function can be used to convert new line entries in a text area into html ________________ tags.
    13·1 answer
  • Explain what happens if you try to open a file for reading that does not exist.
    10·1 answer
  • A nested folder can best be described as what?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!