Question: Java Question. I'm getting an error below: Exception in thread main java.lang.Error: Unresolved compilation problem: a3Age cannot be resolved to a variable import java.io.IOException; import

Java Question. I'm getting an error below:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: a3Age cannot be resolved to a variable

import java.io.IOException; import java.util.Scanner; import java.util.*;

public class Questions { public static void main(String[] args) throws IOException { Scanner input = new Scanner(System.in); boolean continueInput = true; java.io.File file = new java.io.File("answers.txt");

if(file.exists()){

System.out.println("File already exists"); System.exit(1); } else { try ( java.io.PrintWriter output = new java.io.PrintWriter(file); ) { //Scanner input = new Scanner(System.in); System.out.print("Q1: What is your first name? "); String a1FirstName = input.nextLine(); System.out.print("Q2: What is your last name? "); String a2LastName = input.nextLine(); do { try { System.out.print("Q3: How old are you? "); int a3Age = input.nextInt(); //input.nextLine(); System.out.println("Your age is" + a3Age); continueInput = false; } catch (InputMismatchException ex) { System.out.println("Try Again. (" + "Incorrect input: an integer is required)"); int a3Age = input.nextInt(); input.nextLine(); } } while (continueInput); System.out.print("Q4: What is your favorite color? "); String a4Color = input.nextLine(); output.println("Q1: What is your first name? " + a1FirstName); output.println("Q2: What is your last name? " + a2LastName); output.println("Q3: How old are you? " + a3Age); output.println("Q4: What is your favorite color? " + a4Color);

} } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!