Question

DEBUGGING. JAVA. Identify the errors in the following. There are no logical errors in this one...

DEBUGGING. JAVA. Identify the errors in the following. There are no logical errors in this one just syntax issues.

//start

import java.util.Scanner;
public class NumbersDemo
{
   public static void main (String args[])
   {
      Scanner kb = new Scanner(System.in);
      int num1, num2;
            System.out.print("Enter an integer >> ");
      num1 = kb.nextInt();
      System.out.print("Enter another integer >> ");
      num2 = kb.nextDouble();
      displayTwiceTheNumber(num1);
      displayNumberPlusFive(num1);
      displayNumberSquared(num1)
      displayTwiceTheNumber(num2);
      displayNumberPlusFive(num2);
      displayNumberSquared(num2);
   }
   public static void displayTwiceTheNumber(double n)
   {
      final int FACTOR = 2;
      System.out.println(n + " times " + FACTOR " is " + (n * FACTOR));
   }
   public static void displayNumberPlusFive(int n)
   {
      final int FACTOR = 5;
      System.out.println(n + " plus " + FACTOR + " is " + (n + FACTOR));
   }
   public static void displayNumberSquared(long n)
   {
      System.out.println(n + " squared is " + (n * n));
   }
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;
public class NumbersDemo
{
    public static void main (String args[])
    {
        Scanner kb = new Scanner(System.in);
        int num1, num2;
        System.out.print("Enter an integer >> ");
        num1 = kb.nextInt();
        System.out.print("Enter another integer >> ");
        num2 = kb.nextInt();
        displayTwiceTheNumber(num1);
        displayNumberPlusFive(num1);
        displayNumberSquared(num1);
        displayTwiceTheNumber(num2);
        displayNumberPlusFive(num2);
        displayNumberSquared(num2);
    }
    public static void displayTwiceTheNumber(double n)
    {
        final int FACTOR = 2;
        System.out.println(n + " times " + FACTOR +" is " + (n * FACTOR));
    }
    public static void displayNumberPlusFive(int n)
    {
        final int FACTOR = 5;
        System.out.println(n + " plus " + FACTOR + " is " + (n + FACTOR));
    }
    public static void displayNumberSquared(long n)
    {
        System.out.println(n + " squared is " + (n * n));
    }
}
Add a comment
Know the answer?
Add Answer to:
DEBUGGING. JAVA. Identify the errors in the following. There are no logical errors in this one...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The files provided in the code editor to the right contain syntax and/or logic errors. In...

    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. // DebugFive2.java // Decides if two numbers are evenly divisible import java.util.Scanner; public class DebugFive2 { public static void main(String args[]) { int num; int num2; Scanner input = new Scanner(System.in); System.out.print("Enter a number "); num = input.nextInteger() System.out.print("Enter another number ");...

  • Java debugging in eclipse package edu.ilstu; import java.util.Scanner; /** * The following class has four independent...

    Java debugging in eclipse package edu.ilstu; import java.util.Scanner; /** * The following class has four independent debugging * problems. Solve one at a time, uncommenting the next * one only after the previous problem is working correctly. */ public class FindTheErrors { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); /* * Problem 1 Debugging * * This problem is to read in your first name, * last name, and current year and display them in *...

  • // 2. Practice debugging this program. It has approximately 22 compiler errors, 1 logic error and...

    // 2. Practice debugging this program. It has approximately 22 compiler errors, 1 logic error and //1 usability error. Identify them all. import java.util.scanner; //This program finds the average of three input values. public class Arithmeticx { public static void main( String [] args ) // declare variables double number1, number2, number3; // input data scanner in = newscanner( ); System.out.print( "Number 1? " ); System.out.print( "Number 2? " ); System.out.print( "Number 3? " ); number 1 = in.nextDouble; number...

  • JAVA I need a switch so that users can input one selection then another. These selections...

    JAVA I need a switch so that users can input one selection then another. These selections are for a simple calculator that uses random numbers 1. + 2. - 3. * 4./ 5. RNG. This has to be simple this is a beginners class. Here is what I have import java.util.Scanner; import java.util.Random; import java.util.*; public class You_Michael02Basic_Calculator {    public static void main(String[] args) {        // Generate random numbers        int num1,num2;        num1 =(int)(Math.random()*100+1);...

  • - Part 1 – 4 Debugging Exercises – there are things wrong – either logic or...

    - Part 1 – 4 Debugging Exercises – there are things wrong – either logic or syntax errors.  Correct the pseudocode and one Java program. Add the corrected code in BOLD and change the corrected color to RED.   Debugging 4:  Add the missing code in bold and red. import java.util.Scanner; public class Airline {             public static void main(String args[])             {                         Scanner s = new Scanner(System.in);                         String passengerName = ""                              String ageString = ""                           int passengerAge = 0                         System.out.println("Enter passenger's name: ");                         passengerName  =...

  • Identify a logical error in the following code and fix it. public class test1 {    ...

    Identify a logical error in the following code and fix it. public class test1 {     public static void main(String[] args){         int total;         float avg;         int a, b, c;         a=10;         b=5;         c=2;         total=a+b+c;         avg=total/3;         System.out.println("Average: "+avg);     } } Answer: Write the output of the program below. import java.util.Scanner; public class test2 { public static void main(String[] arg){ int psid; String name; Scanner input=new Scanner(System.in); System.out.println("Enter your PSID"); psid=input.nextInt(); System.out.println("Enter your...

  • Could someone re-write this code so that it first prompts the user to choose an option...

    Could someone re-write this code so that it first prompts the user to choose an option from the calculator (and catches if they enter a string), then prompts user to enter the values, and then shows the answer. Also, could the method for the division be rewritten to catch if the denominator is zero. I have the bulk of the code. I am just having trouble rearranging things. ------ import java.util.*; abstract class CalculatorNumVals { int num1,num2; CalculatorNumVals(int value1,int value2)...

  • Correct the five syntax, run-time or logic errors that are found in the CountAndAverageNumbers.java file. Link...

    Correct the five syntax, run-time or logic errors that are found in the CountAndAverageNumbers.java file. Link to the file: CountAndAverageNumbers.javaPreview the document. Make sure you include comments in your code where errors were corrected. If you do not flag each error with a comment, points will be deducted. Upload the corrected .java file here. The output of the corrected file looks like the following: Debug4Output.PNG This program reads an unspecified number of integers, determines how many positive and negative values...

  • JAVA HELP: Directions Write a program that will create an array of random numbers and output...

    JAVA HELP: Directions Write a program that will create an array of random numbers and output the values. Then output the values in the array backwards. Here is my code, I am having a problem with the second method. import java.util.Scanner; import java.util.Random; public class ArrayBackwards { public static void main(String[] args) { genrate(); print(); } public static void generate() { Scanner scanner = new Scanner(System.in);    System.out.println("Seed:"); int seed = scanner.nextInt();    System.out.println("Length"); int length = scanner.nextInt(); Random random...

  • The following code is a Java code for insertion sort. I would like this code to...

    The following code is a Java code for insertion sort. I would like this code to be modified by not allowing more than 10 numbers of integer elements (if the user enters 11 or a higher number, an error should appear) and also finding the range of the elements after sorting. /* * Java Program to Implement Insertion Sort */ import java.util.Scanner; /* Class InsertionSort */ public class InsertionSortTwo { /* Insertion Sort function */ public static void sort( int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT