Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 3, Problem 15E
Repeat Exercise 13, but use a multibranch if-else statement instead of a switch statement.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Give an example of a nested if-else statement.
Write a program that inputs a number and a letter and then decides whether the square is a black or white square. Hint: For letters a, c, e, g you may apply a modulus 2 operation on the number to decide the result to be a black or white square. The situation is reversed for the rest of the letters. You may use a switch selection in combination with an if/else selection statement or you may use nested if/else selection statements with logical operators. You may assume the user enters valid values.
Sample outputs:
Enter square value: e 4
White square
Enter square value: g 7
Black square
C++
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.
Chapter 3 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Ch. 3.1 - Suppose goals is a variable of type int. Write an...Ch. 3.1 - Suppose goals and errors are variables of type...Ch. 3.1 - Suppose salary and deductions are variables of...Ch. 3.1 - Suppose speed and visibility are variables of type...Ch. 3.1 - Suppose salary and bonus are variables of type...Ch. 3.1 - Assume that nextWord is a string variable that has...Ch. 3.1 - Prob. 7STQCh. 3.1 - What output is produced by the following code? int...Ch. 3.1 - Suppose you change the code in the previous...Ch. 3.1 - What output is produced by the following code? int...
Ch. 3.2 - Suppose number is a variable of type int that has...Ch. 3.2 - What output is produced by the following...Ch. 3.2 - What output is produced by the following...Ch. 3.2 - What output is produced by the following...Ch. 3.3 - What output is produced by the following code?Ch. 3.3 - Suppose you change the code in the previous...Ch. 3.3 - What output is produced by the following code?Ch. 3.3 - What output is produced by the following code?Ch. 3.3 - Suppose you change the first line of the code in...Ch. 3.3 - Prob. 20STQCh. 3.4 - Prob. 21STQCh. 3.4 - Prob. 22STQCh. 3.4 - Write code for a JOptionPane dialog that will ask...Ch. 3 - Write a fragment of code that will test whether an...Ch. 3 - Write a fragment of code that will change the...Ch. 3 - Suppose you are writing a program that asks the...Ch. 3 - Prob. 4ECh. 3 - Consider the following fragment of code: What is...Ch. 3 - We would like to assess a service charge for...Ch. 3 - What is the value of each of the following boolean...Ch. 3 - The following code fragment will not compile. Why?...Ch. 3 - Prob. 9ECh. 3 - Consider the boolean expression (2 5) (x 100))....Ch. 3 - Write a switch statement to convert a letter grade...Ch. 3 - Consider the previous question, but include + or ...Ch. 3 - Imagine a program that displays a menu of five...Ch. 3 - Repeat the previous exercise, but define an...Ch. 3 - Repeat Exercise 13, but use a multibranch if-else...Ch. 3 - Given that the int variable temp contains a...Ch. 3 - Write Java statements that create a yes-or-no...Ch. 3 - A number x is divisible by y if the remainder...Ch. 3 - Write a program to read in three nonnegative...Ch. 3 - Write a program that reads three strings from the...Ch. 3 - Write a program that reads a one-line sentence as...Ch. 3 - Write a program that allows the user to convert a...Ch. 3 - Write a program that inputs an integer. If the...Ch. 3 - Prob. 7PCh. 3 - Repeat Programming Project 5 of Chapter 2, but...Ch. 3 - Repeat any of the previous Practice Programs using...Ch. 3 - Suppose that we are working for an online service...Ch. 3 - Write a program that reads a string from the...Ch. 3 - Repeat the calorie-counting program described in...Ch. 3 - Repeat Programming Project 5 but in addition ask...Ch. 3 - Repeat Programming Project 11 in Chapter 2, but if...Ch. 3 - Write a program to play the rock-paper-scissor...Ch. 3 - Prob. 9PPCh. 3 - Repeat Programming Project 8 in Chapter 1, but add...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Modify your program for Programming Project 2 so that it uses 12-hour notation, such as 3:45 PM.
Problem Solving with C++ (10th Edition)
The following statement should determine if x is not greater than 20. What is wrong with it? if (!x 20)
Starting Out with C++ from Control Structures to Objects (8th Edition)
Describe a method that can be used to gather a piece of data such as the users age.
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
In Exercises 41 through 46, identify the errors.
Introduction To Programming Using Visual Basic (11th Edition)
T F A class template may not be derived from another class template.
Starting Out with C++ from Control Structures to Objects (9th Edition)
Draw state diagrams of the control software for: an automatic washing machine that has different programs for d...
Software Engineering (10th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- 1. By using the aid of flowchart(s), explain the difference between if selection and if.. else selection.arrow_forwardWrite a program to find the summation of two degrees, Find the grade using If - Block statement and display the value of grade in a text box,use the grades (very good, good, passed)arrow_forwardtrue or false 1. Determine if the expression: ! (!(a>b) || ( a==c) || ( a>=b ) ) is True or False. Given the value of a is 2, b is 10 and c is -5. 2. Determine if the expression: ! (!(a>b) || ( a==c) || ( a>=b ) ) is True or False. Given the value of a is 2, b is 10 and c is -5.arrow_forward
- 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". Do NOT end with newline.arrow_forwardWrite an if-else statement with multiple branches. If given Year is 2101 or greater, print "Distant future" (without quotes). Else, if given Year is 2001 or greater (2001-2100), print "21st century". Else, if given Year is 1901 or greater (1901-2000), print "20th century". Else (1900 or earlier), print "Long ago". End with a newline. Remember to use printin instead of print to output a newline. 439894.2564214.qx3zqy7 1 import java.util.Scanner; 2 3 public class YearChecker { 4 5 6 7 8 9 10 11 12 13 } public static void main (String[] args) { Scanner scnr = new Scanner(System.in); int givenYear; } givenYear = scnr.nextInt (); /* Your solution goes here */arrow_forwardHW3: Write a program in C language by using if statement for a lift control system, for your information the maximum weight is 240kg and for five floors.arrow_forward
- Using C Languagearrow_forwardCompare the use of if-else statements with the use of conditional operators.arrow_forwardC#: Write a program that asks the user to enter a month (1 for January, 2 for February, etc.) and then prints the number of days in the month. For February, print “28 days”. Enter a month: 5 30 days Do not use a separate if/else branch for each month. Use Boolean operators.arrow_forward
- Instructions Write the pseudocode and draw the flowchart of the solution for each of the following problems:arrow_forwardWrite a program that asks the user to enter a month (1 for January, 2 for February, etc.) and then prints the number of days in the month. For February, print “28 days”. Enter a month: 5 30 days Do not use a separate if/else branch for each month. Use Boolean operators.arrow_forwardWrite down a regular expression for floating-point numbers in Scientific notation. Firstwrite a regular expression for signed numbers and number with a decimal point and thenuse these regular expressions to write the regular expression for scientific notation.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Control Structure in Data Structure - Data Structures - Computer Science Class 12; Author: Ekeeda;https://www.youtube.com/watch?v=9FTw2pXLhv4;License: Standard YouTube License, CC-BY