Something could go wrong with the following code. Identify and fix the problem.
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
Absolute Java (6th Edition)
Additional Engineering Textbook Solutions
Modern Database Management
Starting Out with Java: From Control Structures through Objects (6th Edition)
Starting Out with Python (4th Edition)
Digital Fundamentals (11th Edition)
Introduction to Programming Using Visual Basic (10th Edition)
Software Engineering (10th Edition)
- Please explain the questions from the code below: 1. What does a switch statement replace? 2. What happens if you remove a break? 3. What is the purpose of default? import java.util.Scanner;import java.util.InputMismatchException; public class Main{public static void main(String [] args){Scanner sc = new Scanner(System.in);int selection = 0; boolean continueLoop = true;do{try{System.out.println("Please enter a number 1 - 5");selection = sc.nextInt();continueLoop = false;}catch(InputMismatchException IME){System.out.println("Invalid input");sc.next();}}while(continueLoop);switch(selection){case 1 : System.out.println("case 1"); break;case 2 : System.out.println("case 2"); break;case 3 : System.out.println("case 3"); break;case 4 : System.out.println("case 4"); break;case 5 : System.out.println("case 5"); break;default : System.out.println("Default");}}}arrow_forwardAnswer the given question with a proper explanation and step-by-step solution. Java: please do not copy/ paste from another solution because it is wrong, I am looking for the same output /******* My question is how can I put the (while loop, do-while, if - else condition) in methods ? below: is a solution how can you fix it ? import java.util.Scanner; public class Main { public static void main(String[] args) { int menuChoice; Scanner keyboard = new Scanner(System.in); while (true) { do { printMenuOptions(); menuChoice = getUserChoice(keyboard); if (menuChoice <= -1) { System.out.println("Invalid number"); } else { if (menuChoice > 5) { System.out.println("Invalid number choose between 0 to 5."); } } } while (menuChoice <= -1 || menuChoice > 5 || menuChoice == 5); // Rest of your code goes here } } public static void printMenuOptions() { System.out.println("what do you like"); System.out.println("1. pepsi"); System.out.println("2. sprit"); System.out.println("3.…arrow_forwardHow do I remove the error from the code? public class MidtermProblems {public class Main { public static void main( String args[] ) { public static String difference(a, b) Scanner input = new Scanner(System.in); int a; int b; int userNum; System.out.print( "Input first integer: " ); a = input.nextInt(); System.out.print( "Input second integer: " ); b = input.nextInt(); if ( a == b ) System.out.printf( "EQUAL\n"); if ( a-b > 0 ) System.out.printf( "a is bigger by " +(a-b=userNum)); if ( a-b < 0 ) System.out.printf( "b is bigger by "+ (b-a=userNum)); } public static void main(String[] args) { System.out.println(MidtermProblems.difference(userNum)); } }arrow_forward
- I have a difficult task that i have been given, the problem is that I just simply cant seem to manage to first print a binary number so if you give me six my code doesnt seem to print the number in binary. but also i need to print it in reverse and my code just doesnt seem to work with that. heres my code import java.util.Scanner; public class LabProgram { public static void main(String[] args) { int x; int output; int i; Scanner input = new Scanner(System.in); x = input.nextInt(); output = x; for ( i = 0; i <= x; i = ++i){ output = x / 2; System.out.println(output); } } } // and bellow this are my instructions . what am i doing wrong what am i missing? ive googled sites and erased portions of code, put in eithers. ive switched back and forth from a for loop to a while loop for awhile now Write a program that takes in a positive integer as input, and…arrow_forwardThis is a debugging problem I am stuck on - The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. This is the code - import java.util.*; public class DebugNine2 { public static void main(String[] args) { Scanner input = new Scanner(System.in); Movie[] movies = new Movie[8]; int i; String message, entry; movies[0] = new Movie("The Godfather", 1972); movies[0] = new Movie("The Good, the Bad, and the Ugly", 1966); movies[0] = new Movie("Pulp Fiction", 1994); movies[0] = new Movie("Shindler's List", 1993); movies[4] = new Movie("Casablanca", 1942); movies[5] = new Movie("Wizard of Oz", 1939); movies[6] = new Movie("Citizen Kane", 1941); movies[7] = new Movie("Some Like It Hot", 1959); System.out.println( "Sort Movies by\n(N)ame, or (Y)ear");…arrow_forwardSo I have what I think the code would be but it doesn't like it. This is the question- Write a program that accepts a number of minutes and converts it both to hours and days. For example, 6000 minutes is 100.0 hours or 4.166666666666667 days. This is the code I have - import java.util.Scanner; public class MinutesConversion { private static Scanner inputDevice; public static void main(String[] args) { int minutes, hours; float days; // float for decimal point inputDevice = new Scanner(System.in); System.out.println("Please enter minutes for conversion >> "); minutes = inputDevice.nextInt(); hours = minutes / 60; days = hours / 24.0f; System.out.println(+ minutes + " minutes is " + hours + " hour(s) or" + days " days"); } }arrow_forward
- I need help with this Java Problem as described in the image below: import java.util.Scanner; public class LabProgram { public static int fibonacci(int n) { /* Type your code here. */ } public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int startNum; startNum = scnr.nextInt(); System.out.println("fibonacci(" + startNum + ") is " + fibonacci(startNum)); }}arrow_forwardSo this is my code but it give me error where did i do wrong? import java.util.Scanner;public class equationy {public static void main(String args[]){Scanner input=new Scanner(System.in);int m,x,c,y;System.out.println("Enter m");m=input.nextInt();System.out.println("Enter x");x=input.nextInt();System.out.println("Enter c");c=input.nextInt();y=m*x+c;System.out.printf("y = %d" , y);}}arrow_forwardI need help with a java code problem that needs this output shown in image below: import java.util.Scanner;import java.util.NoSuchElementException; public class LabProgram { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int val1 = 0, val2 = 0, val3 = 0; // Initialize the variables int max; int inputCounter = 0; // Counter to keep track of the number of inputs read try { String inputLine = scnr.nextLine(); String[] parts = inputLine.split(" "); if (parts.length > 0 && !parts[0].isEmpty()) { val1 = Integer.parseInt(parts[0]); inputCounter++; } if (parts.length > 1 && !parts[1].isEmpty()) { val2 = Integer.parseInt(parts[1]); inputCounter++; } if (parts.length > 2 && !parts[2].isEmpty()) { val3 =…arrow_forward
- What is the output of the following java code? Scanner input = new Scanner("15 10"); String sum = input.nextInt()+ input.nextInt(); System.out.println(sum); 150 1510 15 10 An error messagearrow_forwardWhat is the algorithm for the following program? public static void main(String[] args){ Scanner in = new Scanner(System.in); String currencyName; double dollarAmount; double exchangeRate; double convertedAmount; System.out.print("Enter the name of currency would you like to convert --> "); currencyName = in.next(); System.out.print("Enter the exchange rate --> "); exchangeRate = in.nextDouble(); System.out.print("Enter amount in dollars to convert --> "); dollarAmount = in.nextDouble(); convertedAmount = dollarAmount/exchangeRate; System.out.println("Currency desired: " + currencyName); System.out.print("Exchange Rate: "); System.out.printf("%.2f", exchangeRate); System.out.println(); System.out.print("Dollars to Convert: "); System.out.printf("%.2f", dollarAmount); System.out.println(); System.out.print(currencyName + " received: "); System.out.printf("%.2f", convertedAmount);…arrow_forwardI need help fixing this java program shown below: import java.util.Scanner;import java.util.InputMismatchException; public class LabProgram { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); /* Type your code here. */ }}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