Question

In: Computer Science

How to fix this debugging in java Problem Debugging This problem is to assign a value...

How to fix this debugging in java

Problem Debugging

This problem is to assign a value to num2 based on the input value of num1. It should then print both numbers.

int num1 = 0;

int num2 = 0;

System.out.print("Enter a number - 1, 2, or 3: ");

num1 = keyboard.nextInt();

if (num1 == 1);

num2 = 2;

else if (num1 == 2);

num2 = 3;

else if (num1 == 3);

num2 = 4;

System.out.println("num1 = " + num1 // + " and num2 = " + num2);

System.out.println("\n");

Solutions

Expert Solution

Light yellow marks indicate the errors and fixed places.

  • Removed ; after the if conditions
  • Defined keyboard parameter
  • Removed \\ in while printing the output

import java.util.Scanner;
public class MyClass {
public static void main(String args[]) {
Scanner keyboard = new Scanner(System.in);
  
int num1 = 0;
  
int num2 = 0;
  
System.out.print("Enter a number - 1, 2, or 3: ");
  
num1 = keyboard.nextInt();
  
if (num1 == 1)
  
num2 = 2;
  
else if (num1 == 2)
  
num2 = 3;
  
else if (num1 == 3)
  
num2 = 4;
  
System.out.println("num1 = " + num1 + " and num2 = " + num2);
  
System.out.println("\n");
}
}


Related Solutions

(in java) Find the maximum value and minimum value in milesTracker. Assign the maximum value to...
(in java) Find the maximum value and minimum value in milesTracker. Assign the maximum value to maxMiles, and the minimum value to minMiles. Sample output for the given program: Min miles: -10 Max miles: 40 given code below (please bold the solution, thank you!) import java.util.Scanner; public class ArraysKeyValue { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); final int NUM_ROWS = 2; final int NUM_COLS = 2; int [][] milesTracker = new int[NUM_ROWS][NUM_COLS]; int...
Why is this java code reaching a deadlock and how to I fix it without serializing...
Why is this java code reaching a deadlock and how to I fix it without serializing the code (i.e. I don't want to do not have the Girl authenticate the Boy then have the Boy authenticate the Girl)? import java.applet.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; // Attempt at a simple handshake. Girl pings Boy, gets confirmation. // Then Boy pings girl, get confirmation. class Monitor { String name; public Monitor (String name) { this.name = name; } public String...
JAVA: How do I fix the last "if" statement in my code so that outputs the...
JAVA: How do I fix the last "if" statement in my code so that outputs the SECOND HIGHEST/MAXIMUM GPA out of the given classes? public class app { private static Object minStudent; private static Object maxStudent; public static void main(String args[ ]) { student st1 = new student("Rebecca", "Collins", 22, 3.3); student st2 = new student("Alex", "White", 19, 2.8); student st3 = new student("Jordan", "Anderson", 22, 3.1); student[] studentArray; studentArray = new student[3]; studentArray[0] = st1; studentArray[1] = st2; studentArray[2]...
In a Java program, how could I write a program that can assign values that would...
In a Java program, how could I write a program that can assign values that would make a rock paper scissors game work? I have a program that will generate a computer response of either rock, paper, or scissors but how can I compare a user input of "rock", "paper", or "scissors" so that we can declare either the user or the computer the winner.
Is police brutality in the U.S a problem? If so, how do Do We fix it?
Is police brutality in the U.S a problem? If so, how do Do We fix it?
(java)Fix the code in this program. Fix lines, add lines… Comment each line that you fixed...
(java)Fix the code in this program. Fix lines, add lines… Comment each line that you fixed … what you did to fix it. import java.util.Scanner; public static void main(String[] args) { // This program Converts grade Points into a Letter grade. int gradePoints == 00; // Declare variable and assign initial value System.out.printl("Enter Grade Points: "; //Input gradePoints; if ( gradePoints >= -42 ) { System.out.println("Grade = A"); } // if true, then ends here, if false drop to next...
In Java form Declare and assign a char variable called myLetter to z. Write a Java...
In Java form Declare and assign a char variable called myLetter to z. Write a Java statement that makes myLetter uppercase. Write a java statement that finds out if myLetter is a digit. Write a java statement that finds out if myLetter is an upper case letter. Assume myLetter = ‘Z’; What is the output for System.out.print(myLetter++); Assume myLetter = ‘Z’; What is the output for System.out.print(++myLetter); Assume myLetter = ‘Z’; What is the output for System.out.print(myLetter--); What happens when...
(IS THERE A PROBLEM THAT IS UNCERTAIN AND NEED TO BE FIX IN THIS PARTNERSHIP AGREEMENT)...
(IS THERE A PROBLEM THAT IS UNCERTAIN AND NEED TO BE FIX IN THIS PARTNERSHIP AGREEMENT) PARTNERSHIP AGREEMENT THIS AGREEMENT made effective as of the 15thday of JANUARY, 2019. BETWEEN: Peter Cutoni (Partner “A”) Of the Hamlet of Bradwardine, in Manitoba - And - Jack Reacher (Partner “B”) Of the City of Brandon, in Manitoba - And - Austin City (Partner “C”) Of the City of Portage la Prairie, in Manitoba WHEREAS the parties are all registered owners, each with...
I keep getting the error below in zbooks. How can I fix this. Thank You JAVA...
I keep getting the error below in zbooks. How can I fix this. Thank You JAVA zyLabsUnitTest.java:14: error: cannot find symbol s = MidtermProblems.difference(75, 75); ^ symbol: method difference(int,int) location: class MidtermProblems 1 error import java.lang.Math; public class MidtermProblems { public static String difference(int a, int b) { int diff = Math.abs(a - b); String ans = "";    if (diff == 0) { ans = "EQUAL";    } else if (diff > 10) { ans = "Big Difference "...
I need to make 2 possible suggestions on how Comcast can fix the problem with their...
I need to make 2 possible suggestions on how Comcast can fix the problem with their customer service, and how Comcast can possibly improve the whole business overall while briefly discussing the impacts of these suggestions. Please put in a paragraph with the heading above, I Must come up with 350 words in total.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT