Concept explainers
Write an if-else statement that outputs the word "High" if the value of the variable score is greater than 100 and outputs "Low" if the value of score is at most 100. The variable score is of type int.
Explanation of Solution
Given: The variable score is of int data type.
To find: The if-else statement to implement the value “High� on the score if it is larger than hundred and “Low� on the score if it is at most hundred.
Solution:
The score is of int data type:
int score;
The if-else statement to implement the value “High� on the score if it is larger than hundred and “Low� on the score if it is at most hundred is:
if(score>100)
// Displaying the message.
System.out.println(“High�);
else
// Displaying the message.
System.out.println(“Low�);
Want to see more full solutions like this?
Chapter 3 Solutions
Absolute Java (6th Edition)
Additional Engineering Textbook Solutions
Concepts of Programming Languages (11th Edition)
Database Concepts (7th Edition)
Starting Out with Java: From Control Structures through Objects (6th Edition)
Digital Fundamentals (11th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
Web Development and Design Foundations with HTML5 (8th Edition)
- Write an if-else statement with multiple branches. If givenYear is 2101 or greater, print "Distant future" (without quotes). Else, if givenYear is 2001 or greater (2001-2100), print "21st century". Else, if givenYear is 1901 or greater (1901-2000), print "20th century". Else (1900 or earlier), print "Long ago". End with a newline. Remember to use println instead of print to output a newline.arrow_forwardWrite an if-else statement with multiple branches.If year is 2101 or later, print "Distant future" (without quotes). Otherwise, if year is 2001 or greater, print "21st century". Otherwise, if year is 1901 or greater, print "20th century". Else (1900 or earlier), print "Long ago".Sample output with input: 1776 Long agoarrow_forwardSuppose number is a variable of type int. Write an if-else statement thatoutputs the word "Positive" if the value of the variable number is greater than0 and outputs the words "Not positive" if the value of number is less than orequal to 0.arrow_forward
- Write an if state to check if the variable, named value, is greater than 5. If so, output the following: "The value is greater than 5"arrow_forwardCreate a Sample Code using Java If Else Statement Problem Here's the given:If - Good Morningelse if - A pleasant morning else - Have a pleasant morning Output: Have a pleasant morningarrow_forwardWrite a program using if-else statements that convert from lbs to kg and vice versa. The input should be type (Lbs or Kg) and a number. The output of the program must be as shown in the examples below. Example 1: Input: Enter your weight: 50 (L)bs or (K)g: L Output: You are 22.5 kilos Example 2: Input: Enter your weight: 50 (L)bs or (K)g: K Output: You are 111.11 pounds Example 3: Input: Enter your weight: 50 (L)bs or (K)g: k Output: Either of your inputs are invalid! pythonarrow_forward
- In which cases you can transform an else-if statements to switch? Provide an example.arrow_forwardThe else in a set of if statements is sometimes called the "catch all"? Is this true or false?arrow_forwardWrite an if statement in Java that prints "Pass" if the grade is greater than or equal to 70 and prints "Fail" if the grade is below 70. If the grade is below 70 print "You have to do Exam2."arrow_forward
- 1. Rewrite the following set of if statements using a nested if-else structure.if (score >= 90) grade = 'A';if (score >= 80 && score < 90) grade = 'B';if (score >= 70 && score < 80) grade = 'C';if (score >= 60 && score < 70) grade = 'D';if (score < 60) grade = 'F';arrow_forwardWrite an if-else statement with multiple branches.If year is 2101 or later, print "Distant future" (without quotes). Otherwise, if year is 2001 or greater, print "21st century". Otherwise, if year is 1901 or greater, print "20th century". Else (1900 or earlier), print "Long ago".Sample output with input: 1776 year = int(input()) ''' Your solution goes here '''arrow_forwardWrite an equivalent if...else if...else statement to replace the following switch statement int cents; switch (cents) { case 1: System.out.println("Cent."); break; case 5: System.out.println("Nickle."); break; case 10: System.out.println("Dime."); break; case 25: System.out.println("Quarter."); break; default: System.out.println("Not a valid value."); }arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education