By now you’ve written a few programs and encountered a few common errors. In thi
ID: 2246509 • Letter: B
Question
By now you’ve written a few programs and encountered a few common errors. In this assignment you will demonstrate your knowledge by fixing the errors you find in the program below. Copy out the text from this document and fix the code. Paste the corrected code in the area below, and make a list of the problems you fixed.
Import java.util.Scanner;
public class Test1 {
public static void main(String[] args) {
Scaner input = new Scanner();
System.out.print("Enter an integer: ");
int v = Input.nextInt());
System.out.printLn("You entered " & v);
System.out,print("Enter a double: ");
double v2 = input.nextInt(),
Systems.println("You entered " & v2);
};
PUT YOUR CORRECTED CODE HERE:
LIST OF PROBLEMS FIXED:
Explanation / Answer
Test1.java
//Import must be starts with small letter
import java.util.Scanner;
public class Test1 {
public static void main(String[] args) {
/* Spelling Mistake in the Scanner class.We have to pass
* System.in as argument to the Scanner class.
*/
Scanner input =new Scanner(System.in);
System.out.print("Enter an integer: ");
//we have to use reference to call the method(Must be Case sensitive)
int v = input.nextInt();
//in println 'l' must be small letter but not capital letter 'L'
//For concatination we have to use '+' symbol
System.out.println("You entered "+v);
//Here we have to use dot instead of ','
//Every statement must end with semicolon but not comma(,)
System.out.print("Enter a double: ");
//To read double value as input.We have to use nextDouble() method
double v2 = input.nextDouble();
/* System class is incorrect.
* we have to write "System.out.println".Here we missed 'out'
*/
System.out.println("You entered " + v2);
//No need to end with semicolon
}
//We missed closing braces
}
________________
Output:
Enter an integer: 34
You entered 34
Enter a double: 56.66
You entered 56.66
_______________Thank You
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.