Results 1 to 3 of 3
  1. #1
    darr is offline Member
    Join Date
    Oct 2010
    Posts
    1
    Rep Power
    0

    Default keep getting error message class, interface, or enum expected

    I am trying to get the following program to work using jcreator but keep getting a message on the highlighted line of code saying class, interface, or enum expected
    /**
    * @(#)java_practice.java
    *
    * java_practice application
    *
    * @author
    * @version 1.00 2010/9/23
    */

    import java.io.*;
    import java.text.*;

    public class java_practice
    {


    public static void main(String[] args)
    throws java.io.IOException
    {
    Sums doingSums = new Sums();
    doingSums.displayResults();

    }
    }

    //class to show the sum and difference of two numbers
    import java.io.*;

    public class Sums
    {
    int firstNumber, secondNumber;
    String inString;

    Sums()
    throws java.io.IOException
    {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

    System.out.println("enter first number: ");
    inString = in.readLine();
    firstNumber = Integer.valueOf(inString).intValue();

    System.out.println("enter second number: ");
    inString = in.readLine();
    secondNumber = Integer.valueOf(inString).intValue();


    }
    int sum ()
    {
    return (firstNumber + secondNumber);
    }

    int difference()
    {
    return (firstNumber - secondNumber);
    }

    public void displayResults()
    {
    System.out.println(firstNumber + " + " + secondNumber + " = " + this.sum() + "\n");
    System.out.println(firstNumber + " - " + secondNumber + " = " + this.difference() + "\n");
    }
    }

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Make sure the Sums class is defined in its own file - Sums.java

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default

    If you want the Sums class in the same source file as the other class, remove the public attribute and move the import statement to the top of the file.

Similar Threads

  1. class, interface or enum expected?
    By Addez in forum New To Java
    Replies: 2
    Last Post: 08-26-2009, 07:54 PM
  2. Replies: 1
    Last Post: 05-31-2009, 10:57 PM
  3. Replies: 1
    Last Post: 05-31-2009, 02:17 PM
  4. Replies: 16
    Last Post: 05-28-2009, 03:41 PM
  5. Replies: 9
    Last Post: 08-08-2007, 07:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •