1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
kolbaska11 [484]
3 years ago
8

If the user enters any operator symbol other than , -, *, or /, then an UnknownOperatorException is thrown and the user is allow

ed to reenter that line of input. Define the class UnknownOperatorException as a subclass of the Exception class. Your program should also handle NumberFormatException if the user enters non-numeric data for the operand.
Computers and Technology
1 answer:
Anna007 [38]3 years ago
7 0

Answer:

Explanation:

The following code is written in Java. It creates the UnknownOperatorException class and catches it if the user enters something other than the valid operators. If so it continues asking the user for a new input. Once a valid operator is entered, it exits the function and prints the operator.

import java.util.Scanner;

class Brainly {

   public static void main(String[] args) {

       char symbol = askForOperand();

       System.out.println("Operand: " + symbol);

   }

   public static char askForOperand() {

       Scanner in = new Scanner(System.in);

       try {

           System.out.println("Enter operator symbol: ");

           char symbol = in.nextLine().charAt(0);

           if ((symbol != '-') && (symbol != '*') && (symbol != '/')) {

               System.out.println(symbol);

               throw new UnknownOperatorException();

           } else {

               return symbol;

           }

       } catch (NumberFormatException | UnknownOperatorException e) {

           System.out.println("Not a valid operand");

           char symbol = askForOperand();

           return symbol;

       }

   }

}

class UnknownOperatorException extends Exception {

   public UnknownOperatorException() {

       System.out.println("Unknown Operator");

   }

}

You might be interested in
Is megan the stallion hot
astraxan [27]

Answer:

Explanation:

Cool

8 0
3 years ago
Read 2 more answers
Where can elicitation techniques be used?
Nikitich [7]

Answer:

An elicitation technique is any of a number of data collection techniques used in anthropology, cognitive science, counseling, education, knowledge engineering, linguistics, management, philosophy, psychology, or other fields to gather knowledge or information from people.

Explanation:

3 0
2 years ago
Can someone URGENTLY help me with my java code (I WILL GIVE BRAINLIEST)!? Ive been working on it for hours and its not working!
vovikov84 [41]

Answer:

Private ListNode intel size

7 0
2 years ago
For the function below, which variables have the same scope?
steposvetlana [31]

Answer:

numB and power

Explanation:

Correct answer edge 2020

5 0
3 years ago
Read 2 more answers
The following SQL statement contains which type of subquery? SELECT title FROM books WHERE EXISTS (SELECT isbn FROM orderitems W
Rudiy27

Answer:

(a) Correlated.

Explanation:

Correlated subquery :These sub queries reference columns from outer table or uses values from outer query.These sub queries are processed atleast once for every row processed.So because of this reason correlated sub queries can be slow.Since the query in the question also uses value from the outer query so it is a correlated query.

4 0
3 years ago
Other questions:
  • Helping people keep track on things is the purpose of_____ A database B table C query D form​
    12·1 answer
  • What does this image represent?
    9·2 answers
  • Then standard toolbar appears whenever you select text true or fals
    15·1 answer
  • What is information associated with a document to help describe that document called?
    12·1 answer
  • Jim wants to buy a car, but he’ll probably only need it for a couple of years. He has a short commute to work, so he won’t be pu
    10·1 answer
  • Refer to the exhibit. A network security analyst is using the Follow TCP Stream feature in Wireshark to rebuild the TCP transact
    8·1 answer
  • Public class Main{ public static void main(String [] args){ String name=WelcomeJava; Runnable r1=() -> System.out.println(nam
    12·1 answer
  • There are types of templates​
    5·1 answer
  • PLEASE ANSWER FAST.one of the barriers for early "talkies" was the need to manually crank the projector and manually synchronize
    13·1 answer
  • What is the function of ALU? <br>​
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!