Concept explainers
Explanation of Solution
Program:
//Import necessary header files
import java.util.*;
//Declare the class
class Main
{
//Main method
public static void main(String[] args)
{
//Initialize the variable
int key = 5;
//Switch statement
switch (key + 1)
{
//Case statement
case 1:
//Print the statement
System.out.println("Cake");
//Break statement
break;
//Case statement
case 2:
//Print the statement
System.out.println("Pie");
//Break statement
break;
//Case statement
case 3:
//Print the statement
System...
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
- What happens when you increase the number ptr by four? Assuming that ptr is a reference to an int, the following is what occurs:arrow_forwardcan you please write it in java.util.scanner form Write a program that prompts the user to enter a number within the range of 1 through 10. The program should display the Roman numeral version of that number. If the number is outside the range of 1 through 10, the program should display an error message. but use switch statement for the program.arrow_forwardQuestion 2: Take a lowercase word as an input from the user. Modify the word in such a way that the letters in the multiple of 3 positions become uppercase except position 0. Lastly, print the newly modified word. [You are not allowed to use upper() method] Sample Input1: jupyter Sample Output1: jupYteR Explanation 1: The characters 'y' and 'r' are in positions 3 and 6 respectively. So, these two characters will be converted to uppercase in the modified string. Sample Input2: python notebook Sample Output2: pytHon noTebOok Explanation 2: The characters 'h', 't', and 'o' are in positions 3, 9, and 12 respectively. So, these three characters will be converted to uppercase in the modified string.arrow_forward
- My code crushes when the user does not select the choice 1/2 for exxample when the user type 3/4 it crushes .. i need help with error handling.. i want the code to say "sorry wrong input number try again" if the user inserted the wrong choice other than 1/2.arrow_forwardWhat is the value of x after the following code executes? double m = 2.67;int x = (int)m;arrow_forwardUse the compareTo method to write code that reads two names from the console and prints the one that comes first in alphabetical order. For example, the program's output might look like the following: Type a name: Tyler Durden Type a name: Marla Singer Marla Singer goes before Tyler Durdenarrow_forward
- Write an application that reads an integer and determines and prints whether it’s odd or even. [Hint: Use the remainder operator. An even number is a multiple of 2. Any multiple of 2 leaves a remainder of 0 when divided by 2.]arrow_forwardNot copy. Giving wrong solutions. In all attempt. Downvotearrow_forwardFix any errors that you find. Use in-line comments to explain how and why you fixed the bugs. Test your program. If you found and fixed all the errors, your code should function as specified: The code should allow users to enter basic, one operator arithmetic expressions using integers or doubles. Then, it should calculate the result of the expression and output the results. For example, if the user inputs “2 + 2,” the calculator should output “2 + 2 = 4.” The operations the program should perform are addition (+), subtraction (-), multiplication (*), and division (/). The user should be asked whether they wish to continue after evaluating each expression. If the user types “Y” or “y,” the program should ask for a new arithmetic expression. If the user types “N” or “n,” the program should terminate with the message: “Program Finished.”arrow_forward
- At a coffee shop , a coffee cost $1. Each coffee you purchase, earns one star. Seven stars earns a free coffee. In turn, that free coffee earns another star. Ask the user how many dollars they will spend, then output the number of coffees that will be given and output the number of stars remaining. Use A loop. Please Write the code in Java and use the test case examples as reference.arrow_forwardWhat is the value of the variable a, after the execution of the following code? int a = 4; int b = a++; Answer:arrow_forwardJava Instructions In this assignment, you will take one Infix expression as input and convert it to both Postfix expression, and Prefix expression Next, you will display the converted versions. See the example below. Finally, you will evaluate the expression, and print out the solution. See the example below. You can assume only integer numbers, +-*/ operators and parentheses are part of the input expression. However, the evaluated output should be of double type. The characters in the input and the output expressions will be separated by single spaces. See the example below. Please follow the same output pattern as shown below. Note: The test run below is just a sample. It does not imply that I will test your code with only this particular input. Make sure you thoroughly test your code before submitting it. Hints You can use Stacks for this task. You can take the input as a string by reading the line from the console. You only need to solve the problem for one input…arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,