Java: An Introduction to Problem Solving and Programming (8th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 9, Problem 2E
Program Plan Intro

Program Plan:

  • • Import required package.
  • • Declare the “Main” class.
    • ○ Define the “main ()” method.
      • ■ Create an object “sc” using “Scanner” class.
      • ■ Declare a boolean variable “flag”.
      • ■ Do the below steps until the user enters other than “y” using “while” condition.
        • • Inside the “try” block,
          • ○ Get two integers from the user.
          • ○ Print the remainder on the screen.
        • • Catch if the operation causes any arithmetic exception.
          • ○ Print the message.
        • • Catch if the user enters other than integers.
          • ○ Print the message.
        • • Ask whether the user wants to continue or not and store the response in a variable “response”.
        • • Check if “response” is equal to “y”.
          • ○ Assign “true” to the Boolean variable.

Blurred answer
Students have asked these similar questions
Write a program that reads integers user_num and div_num as input, and output the quotient (user_num divided by div_num). Use a try block to perform all the statements. Use an except block to catch any ZeroDivisionError as a variable and output "Zero Division Exception: " followed by the exception message from the variable. Use another except block to catch any ValueError caused by invalid input as a variable and output "Input Exception: " followed by the exception message from the variable. Note: ZeroDivisionError is raised when a division by zero happens. ValueError is raised when a user enters a value of different data type than what is defined in the program. Do not include code to raise any exception in the program. (in Python)
Write a program that reads integers user_num and div_num as input, and output the quotient (user_num divided by div_num). Use a try block to perform all the statements. Use an except block to catch any ZeroDivisionError as a variable and output "Zero Division Exception: " followed by the exception message from the variable. Use another except block to catch any ValueError caused by invalid input as a variable and output "Input Exception: " followed by the exception message from the variable. Note: ZeroDivisionError is raised when a division by zero happens. ValueError is raised when a user enters a value of different data type than what is defined in the program. Do not include code to raise any exception in the program. Ex: If the input of the program is: 15 3 the output of the program is: 5 Ex: If the input of the program is: 10 0 the output of the program is: Zero Division Exception: integer division or modulo by zero Ex: If the input of the program is: 15.5 5 the output of…
Take two integers from the user, Write a program in Java to divide a number by another. Point to be NOTED: User may give "string or o“ as divider intentionally or by mistake. You must handle all types of exception, But the program should not stop if there is any kind of error or exception. Your program should provide as many chances as user need to complete the calculation. The program will immediately exit after successfully dividing the 1st number by 2nd number.

Chapter 9 Solutions

Java: An Introduction to Problem Solving and Programming (8th Edition)

Knowledge Booster
Background pattern image
Computer Science
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
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT