Question

I am getting an error from eclipse stating that: Exception in thread "main" java.lang.Error: Unresolved compilation...

I am getting an error from eclipse stating that:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at EvenOdd.main(EvenOdd.java:10)

I am unable to find what I can do to fix this issue. Can you please assist?
My code is below:

import java.util.InputMismatchException;
import java.util.Scanner;

public class EvenOdd {

   public static void main(String[] args) {
       Scanner input = new Scanner(System.in);
       System.out.println("Welcome to this Odd program!");
       int userInput1 = input.nextInt();
   }
  
   public static void oddOrEven (int userInput)
       throws InputMismatchException {
       @SuppressWarnings("resource")
       Scanner input = new Scanner(System.in);
       int userInput1 = input.nextInt();
       boolean continueLoop = true;


   do {
               if(userInput1 % 2 == 0) {
                   System.out.println(userInput1 + " is even");
               }
               else {
                   System.out.println(userInput1 + " is odd");
               }
               if(userInput1 == -999) {
                   continueLoop = false;
                   System.out.println("Thank you for using this Odd program!");
                  
               }
               try {
                   System.out.println("Please enter an integer or -999 to quit: ");
                   System.out.println("You have entered: " + userInput1);
                   continueLoop = true;
               }
                   catch (InputMismatchException e) {
                       System.out.printf("%nException: %s%n\",\r\n" + e);
                       input.nextLine();
                       System.out.printf("You must enter integers. Please try again.%n%n");
           }

       }while (continueLoop);
   }
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.InputMismatchException;
import java.util.Scanner;

public class EvenOdd {

   public static void main(String[] args) {
       System.out.println("Welcome to this Odd program!");
       oddOrEven(0);
   }

   public static void oddOrEven(int userInput) throws InputMismatchException {
       @SuppressWarnings("resource")
       Scanner input = new Scanner(System.in);
       int userInput1 = input.nextInt();
       boolean continueLoop = true;

       do {
           if (userInput1 % 2 == 0) {
               System.out.println(userInput1 + " is even");
           } else {
               System.out.println(userInput1 + " is odd");
           }
           if (userInput1 == -999) {
               System.out.println("Thank you for using this Odd program!");
               break;

           }
           try {
               System.out.println("Please enter an integer or -999 to quit: ");
               userInput1 = input.nextInt();
               System.out.println("You have entered: " + userInput1);
           } catch (InputMismatchException e) {
               System.out.printf("%nException: %s%n\",\r\n" + e);
               input.nextLine();
               System.out.printf("You must enter integers. Please try again.%n%n");
           }

       } while (continueLoop);
   }
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
I am getting an error from eclipse stating that: Exception in thread "main" java.lang.Error: Unresolved compilation...
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
  • I need help debugging this Java program. I am getting this error message: Exception in thread...

    I need help debugging this Java program. I am getting this error message: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2 at population.Population.main(Population.java:85) I am not able to run this program. ------------------------------------------------------------------- import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Scanner; /* Linked list node*/ class node { long data; long year; String country; node next; node(String c,long y,long d) { country=c; year=y; data = d; next = null; } } public class Population { private static node head; public static void push(String...

  • I am currently doing homework for my java class and i am getting an error in...

    I am currently doing homework for my java class and i am getting an error in my code. import java.util.Scanner; import java.util.Random; public class contact {       public static void main(String[] args) {        Random Rand = new Random();        Scanner sc = new Scanner(System.in);        System.out.println("welcome to the contact application");        System.out.println();               int die1;        int die2;        int Total;               String choice = "y";...

  • The Calculator Class Create an application dlass called Colcustor with the following members Methods Retuns firtNumber...

    The Calculator Class Create an application dlass called Colcustor with the following members Methods Retuns firtNumber secondumber static void mainsering Asks for two integer undan uiet", ..",ЛТеп shows the result according to Note Use the attached example program and add required methods. Then une a switch tructure in the try black to call proper method according to the input operator Sample Output 1 : 2074 Sample Output 2 D1VLdeBy LerOWLthEkceptionHahaling-Jav / Handling ArithmeticExceptions and InputMismatchExceptions. import java.util.InputMismatchException; import java.util.Scanner; public...

  • 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...

  • I keep getting the compilation error: pass the filename from command line arguement... Can you please...

    I keep getting the compilation error: pass the filename from command line arguement... Can you please tell me what im doing wrong? here is the code: import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class ShipDemo { public static void main(String[] args) { String companyName; int num_ships, total_passengers=0, total_tonnage=0; Ship[] shipInventory; try { if(args.length == 1) { File file = new File(args[0]); Scanner fileScan = new Scanner(file); companyName = fileScan.nextLine(); num_ships = fileScan.nextInt(); shipInventory = new Ship[num_ships]; int n=0; String type,name;...

  • How would I try/catch recovery from a format mismatch error? The scanner needs to continue prompting...

    How would I try/catch recovery from a format mismatch error? The scanner needs to continue prompting until the user enters a valid number. I know that I would need to try n = kbd.nextInt(); and catch a InputMismatchException and if n<1 or n>100 then I need to print Out of Range Exception. Must be in 1..100. However, I am unsure how to loop all of that. import java.io.*; import java.util.*; public class Lab5 { public static void main( String args[]...

  • Java. Java is a new programming language I am learning, and so far I am a...

    Java. Java is a new programming language I am learning, and so far I am a bit troubled about it. Hopefully, I can explain it right. For my assignment, we have to create a class called Student with three private attributes of Name (String), Grade (int), and CName(String). In the driver class, I am suppose to have a total of 3 objects of type Student. Also, the user have to input the data. My problem is that I can get...

  • The part in bold is giving me an error. Ther error is that I cant convert...

    The part in bold is giving me an error. Ther error is that I cant convert an int to a boolean. The program asks the user to input two integer values and determines whether the first is divisible (without a remainder) by the second import java.util.Scanner; public class CheckDivisible { int isDivisible(int dividend, int divisor) { if(dividend % divisor == 0) return 1; else return 0; } public static void main(String[] args) { int dividend = 0; int divisor =...

  • How can I make this program sort strings that are in a text file and not...

    How can I make this program sort strings that are in a text file and not have the user type them in? I need this done by 5:00 AM EST tommorow please. import java.util.*; public class MergeDemo { public static void main(String args[]) { Scanner input=new Scanner(System.in); System.out.print("How many lines to be sorted:"); int size=input.nextInt(); String[] lines=new String[size]; lines[0]=input.nextLine(); System.out.println("please enter lines..."); for(int i=0;i { lines[i]=input.nextLine(); } System.out.println(); System.out.println("Lines Before Sorting:"); System.out.println(Arrays.toString(lines)); mergeSort(lines); System.out.println(); System.out.println("Lines after Sorting:"); System.out.println(Arrays.toString(lines)); } public...

  • Need Help ASAP!! Below is my code and i am getting error in (public interface stack)...

    Need Help ASAP!! Below is my code and i am getting error in (public interface stack) and in StackImplementation class. Please help me fix it. Please provide a solution so i can fix the error. thank you.... package mazeGame; import java.io.*; import java.util.*; public class mazeGame {    static String[][]maze;    public static void main(String[] args)    {    maze=new String[30][30];    maze=fillArray("mazefile.txt");    }    public static String[][]fillArray(String file)    {    maze = new String[30][30];       try{...

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