![Introduction to Java Programming and Data Structures, Comprehensive Version, Student Value Edition (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780134671604/9780134671604_largeCoverImage.gif)
Concept explainers
a.
Explanation of Solution
Program code:
//Main class
class Main
{
//Main method
public static void main(String[] args)
{
//Declare the variable
int number = 14;
//int number = 15;
//int number = 30;
//Check if the number is even
if(number % 2 == 0)
//Print the statement
System.out.println(number + " is even");
//Check if the number is multiple of 5
if(number % 5 == 0)
//Print the statement
System.out.println(number + " is multiple of 5");
}
}
Output:
Here, whatever the number is given both the “if” condition is checked.
If the value “14” is assigned to the variable “number”:
“14 is even” gets printed because, “14” is an even number and the 1st “if” condition gets executed...
b.
Explanation of Solution
Program code:
//Main class
class Main
{
//Main method
public static void main(String[] args)
{
//Declare the variable
int number = 14;
//int number = 15;
//int number = 30;
//Check if the number is even
if(number % 2 == 0)
//Print the statement
System.out.println(number + " is even");
//Check if the number is multiple of 5
else if(number % 5 == 0)
//Print the statement
System.out.println(number + " is multiple of 5");
}
}
Output:
Here, if the “if” statement is true, then “else if” part does not gets executed...
![Check Mark](/static/check-mark.png)
Want to see the full answer?
Check out a sample textbook solution![Blurred answer](/static/blurred-answer.jpg)
Chapter 3 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version, Student Value Edition (11th Edition)
- This Code print the first occurrences of x, Please Modify the code to print the last occurrences of x and print how many times it exists? ( with explanation for each line if possible) many thanks.arrow_forwardAnswer the following question in R and show the code.arrow_forwardWhat is the output of the following code segment?inta=3,b=4;if(ab)Write(Y);WriteLine(Z); Y Z YZ nothingarrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337102100/9781337102100_smallCoverImage.gif)
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)