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...
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Introduction to Java Programming and Data Structures Comprehensive Version (11th Edition)
- 4. Odd-Even-inator by CodeChum Admin My friends are geeking out with this new device I invented. It checks if a number is even or odd! ? Do you want to try it out? Instructions: In the code editor, you are provided with a function that checks whether a number is even or odd. Your task is to ask the user for the number of integer, n, they want to input and then the actual n number values. For each of the number, check whether it is even or odd using the function provided for you. Make sure to print the correct, required message. Input 1. Integer n 2. N integer valuesarrow_forward:Write. program to find maximum number between three numbers?arrow_forward(Python matplotlib or seaborn) CPU Usage We have the hourly average CPU usage for a worker's computer over the course of a week. Each row of data represents a day of the week starting with Monday. Each column of data is an hour in the day starting with 0 being midnight. Create a chart that shows the CPU usage over the week. You should be able to answer the following questions using the chart: When does the worker typically take lunch? Did the worker do work on the weekend? On which weekday did the worker start working on their computer at the latest hour? cpu_usage = [ [2, 2, 4, 2, 4, 1, 1, 4, 4, 12, 22, 23, 45, 9, 33, 56, 23, 40, 21, 6, 6, 2, 2, 3], # Monday [1, 2, 3, 2, 3, 2, 3, 2, 7, 22, 45, 44, 33, 9, 23, 19, 33, 56, 12, 2, 3, 1, 2, 2], # Tuesday [2, 3, 1, 2, 4, 4, 2, 2, 1, 2, 5, 31, 54, 7, 6, 34, 68, 34, 49, 6, 6, 2, 2, 3], # Wednesday [1, 2, 3, 2, 4, 1, 2, 4, 1, 17, 24, 18, 41, 3, 44, 42, 12, 36, 41, 2, 2, 4, 2, 4], # Thursday [4, 1, 2, 2, 3, 2, 5, 1, 2, 12, 33, 27, 43, 8,…arrow_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 LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT