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)
- What is the result of the following code? x = 10 y = 15 print(x = y)arrow_forwardWrite code that iterates while userNum is less than 12. Each iteration: Put userNum to output. Then, put "/" to output. Then, assign userNum with userNum multiplied by 3.arrow_forwardHow does the character ‘A’ compare to the character ‘B’?a. ‘A’ is greater than ‘B’b. ‘A’ is less than ‘B’c. ‘A’ is equal to ‘B’d. You cannot compare charactersarrow_forward
- Please written by computer source Both 169 and 961 are the square of a prime. 169 is the reverse of 961. We call a number a reversible prime square if: It is not a palindrome, and It is the square of a prime, and Its reverse is also the square of a prime. 169 and 961 are not palindromes, so both are reversible prime squares. Find the sum of the first 50 reversible prime squares. in javaarrow_forwardi need answer very quicklyarrow_forwarduse python language only, no c++ or otherarrow_forward
- After typing the code, I input 1900. I'm getting an error, my output "20th century" is wrong. Expected output "Long ago."arrow_forwardThe correct statements are: For L = 0, L* = {e} For L = {e}, L* = {e} OL+ = LL* L* = LL+arrow_forwardUsing functions, create a program that reads three integer values, and then determines whether they can be the sides of a triangle.(the numbers. Notes: The values can represent the sides of a triangle if the sum of any two sides of the triangle is greater than the third sidearrow_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