Describe the scope error in the following program and explain how to fix it.
public class Conversation
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("What is your first name?");
String input = in.next();
System.out.println("Hello, " + input);
System.out.print("How old are you? ");
int input = in.nextInt();
input++;
System.out.println("Next year, you will be " + input);
}
}
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
Big Java Late Objects
Additional Engineering Textbook Solutions
Starting Out with C++: Early Objects (9th Edition)
C Programming Language
Starting Out with Java: From Control Structures through Objects (6th Edition)
Java: An Introduction to Problem Solving and Programming (7th Edition)
Computer Science: An Overview (12th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
- class Output{public static void main(String args[]){Integer i = new Integer(557);float x = i.floatValue();System.out.print(x);}} What will the given code prints on the output screen.arrow_forwardpublic class Test { } public static void main(String[] args){ int a = 10; System.out.println(a*a--); }arrow_forward// ArtShow.java - This program determines if an art show attendee gets a 5% discount // for preregistering. // Input: Interactive. // Output: A statement telling the user if they get a discount or no discount. import java.util.Scanner; public class ArtShow { public static void main(String args[]) { Scanner s = new Scanner(System.in); String registerString; System.out.println("Did you preregister? Enter Y or N: "); registerString = s.nextLine(); // Test input here. If Y, call discount(), else call noDiscount(). System.exit(0); } // End of main() method. // Write discount method here. // Write noDiscount method here. } // End of ArtShow class.arrow_forward
- Fix all errors to make the code compile and complete. //MainValidatorA3 public class MainA3 { public static void main(String[] args) { System.out.println("Welcome to the Validation Tester application"); // Int Test System.out.println("Int Test"); ValidatorNumeric intValidator = new ValidatorNumeric("Enter an integer between -100 and 100: ", -100, 100); int num = intValidator.getIntWithinRange(); System.out.println("You entered: " + num + "\n"); // Double Test System.out.println("Double Test"); ValidatorNumeric doubleValidator = new ValidatorNumeric("Enter a double value: "); double dbl = doubleValidator.getDoubleWithinRange(); System.out.println("You entered: " + dbl + "\n"); // Required String Test System.out.println("Required String Test:"); ValidatorString stringValidator = new ValidatorString("Enter a required string: "); String requiredString =…arrow_forwardFix all errors to make the code compile and complete.//MainValidatorA3 public class MainA3 { public static void main(String[] args) { System.out.println("Welcome to the Validation Tester application"); // Int Test System.out.println("Int Test"); ValidatorNumeric intValidator = new ValidatorNumeric("Enter an integer between -100 and 100: ", -100, 100); int num = intValidator.getIntWithinRange(); System.out.println("You entered: " + num + "\n"); // Double Test System.out.println("Double Test"); ValidatorNumeric doubleValidator = new ValidatorNumeric("Enter a double value: "); double dbl = doubleValidator.getDoubleWithinRange(); System.out.println("You entered: " + dbl + "\n"); // Required String Test System.out.println("Required String Test:"); ValidatorString stringValidator = new ValidatorString("Enter a required string: "); String requiredString =…arrow_forwardRemaining Time: 1 hour, 28 minutes, 35 seconds. * Question Completion Status: QUESTTON 11 There are five syntax errors in the following java program. Explain them by mentioning the line number with each error. public class public static void main (String [] args) { { double a = 9; 4 double b = 9.0; int x; System.out.println ("Sum of a and b is if( a = b) + (a+b)) 80 X = a; switch (a+b) { case 0: System.out.println (x); default: System.out.println (x) ; 10 11 12 13 14arrow_forward
- javaarrow_forwardFollow these steps: Open the Java file Errors.java. Attempt to compile the program. You'll notice the compilation will fail due to some errors. Fix all the compilation errors and compile the program again. Every time you fix an error, add a comment to the line you fixed and indicate which of the three types of errors it was. Now run the program. Once again, you'll encounter some errors (this time, runtime errors). Fix these errors and run the program once again to see if it works. Now run the program and notice the output. You'll notice that there are some logical errors in the code. Fix these errors and run the program once again to see if it now correctly displays what it should.arrow_forwardExamine this code and determine what happens when it is run: 1 public class Test { int x; 2 3 public Test(String t){ System.out.println("Test"); } public static void main(String[] args) { Test test = new Test ("boo"); System.out.println(test.x); } 4 5 6 7 8 10 } The program has a compile error because Test does not have a default constructor. The program has a compile error because System.out.println method cannot be invoked from the constructor. ) The program runs successfully and prints out: Test O The program has a compile error because you cannot create an object from the class that defines the object.arrow_forward
- Input class Output { public static void main(String args[]) { int x , y = 1; x = 10; if (x != 10 && x / 0 == 0) System.out.println(y); else System.out.println(++y); } } Find outputarrow_forwardQuestion public class MyProgram { if (h 18) { public static void main(String[] args) { int h=10, t-22; System.out.print ("Good "); } } else } } What is the output displayed by the following lines of code?" System.out.print ("Morning"); t = t + 2; if (t > 30) System.out.println(" Every one!"); System.out.println("The Your answer system.out.print("Evening"); t = t + 5; temperature is " System.out.println(" Brink water?"); Degree.");arrow_forwardpublic static void printIt(int value) { if(value 0) { } System.out.println("Play a paladin"); System.out.println("Play a white mage"); }else { } }else if (value < 15) { System.out.println("Play a black mage"); System.out.println("Play a monk"); } else { public static void main(String[] args) { printit (5); printit (10); printit (15); Play a black mage Play a white mage (nothing/they are all printed) Play a paladin Play a monkarrow_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