Respuesta :
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
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.