Hi, I recently installed jcreator and jdk 1.6
i was testing out the program to see if it worked correctly
I used a really simple program(below) but whenever I type a second integer, the error "Make sure you enter an integer" appears, I've tried a few simple programs to the same affect. What is wrong

class Oneb
//
// A simple program that calculates the sum, product and average of three numbers
{
	public static void main(String args[])
	{

		int n1;
		int n2;
		int n3;
		int sum;
		int product;
		double average;

		System.out.print("Enter the first number -> ");
		n1=EasyIn.getInt();

		System.out.print("Enter the second number -> ");
		n2=EasyIn.getInt();

		System.out.print("Enter the third number -> ");
		n3=EasyIn.getInt();


		sum=n1+n2+n3;
		product=n1*n2*n3;
		average=sum/3;

		System.out.println("The sum of the three numbers is " + sum);
		System.out.println("The product of the three numbers is " + product);
		System.out.println("The average of the three numbers is " + average);
	}
}

What is EasyIn? Is this your own class? It is not a java class.

Normally, people use the Scanner class to take input.

Scanner input = new Scanner(System.in);
n1 = input.nextInt();

I've always used that easy in, its in the right folder too

So obviously you are not entering integer if EasyIn works correctly

That makes no sense pbl, I've used easyin countless times entering integers

Well, the print out of the error "Make sure you enter an integer" is not present in this class, assuming that message comes from your EasyIn class, I would assume the problem lies there. (perhaps you accidentally changed something)

This is the code for EasyIn

// EasyIn.java

import java.io.*;

public abstract class EasyIn
{
  static String s = new String();
  static byte[] b = new byte[512];
  static int bytesRead = 0;

  public static String getString()
  {
     boolean ok = false;
     while(!ok)
     {
        try
        {
           bytesRead = System.in.read(b);
           s = new String(b,0,bytesRead-1);
           s=s.trim();
           ok = true;
        }
        catch(IOException e)
        {
            System.out.println(e.getMessage());
        }
     }
	return s;
   }

   public static int getInt()
   {
      int i = 0;
      boolean ok = false;
      while(!ok)
      {
         try
         {
             bytesRead = System.in.read(b);
             s = new String(b,0,bytesRead-1);
               i = Integer.parseInt(s.trim());
             ok = true;
         }
         catch(NumberFormatException e)
         {
            System.out.println("Make sure you enter an integer");
         }
         catch(IOException e)
         {
             System.out.println(e.getMessage());
         }
     }
     return i;
 }

 public static byte getByte()
 {
     byte i = 0;
     boolean ok = false;
     while(!ok)
     {
        try
        {
            bytesRead = System.in.read(b);
            s = new String(b,0,bytesRead-1);
            i = Byte.parseByte(s.trim());
            ok = true;
        }
        catch(NumberFormatException e)
        {
            System.out.println("Make sure you enter a byte");
        }
        catch(IOException e)
        {
             System.out.println(e.getMessage());
        }
     }
     return i;
 }

 public static short getShort()
 {
     short i = 0;
     boolean ok = false;
     while(!ok)
     {
        try
        {
            bytesRead = System.in.read(b);
            s = new String(b,0,bytesRead-1);
            i = Short.parseShort(s.trim());
            ok = true;
        }
        catch(NumberFormatException e)
        {
            System.out.println("Make sure you enter a short integer");
        }
        catch(IOException e)
        {
             System.out.println(e.getMessage());
        }
     }
     return i;
 }


 public static long getLong()
 {
    long l = 0;
    boolean ok = false;
    while(!ok)
    {
       try
       {
           bytesRead = System.in.read(b);
             s = new String(b,0,bytesRead-1);
           l = Long.parseLong(s.trim());
           ok = true;
       }
       catch(NumberFormatException e)
       {
           System.out.println("Make surre you enter a long integer");
       }

       catch(IOException e)
       {
            System.out.println(e.getMessage());
       }
    }
    return l;
 }


 public static double getDouble()
 {
    double d = 0;
    boolean ok = false;
    while(!ok)
    {
        try
        {
             bytesRead = System.in.read(b);
             s = new String(b,0,bytesRead-1);
             d = (Double.valueOf(s.trim())).doubleValue();
             ok = true;
        }
        catch(NumberFormatException e)
        {
             System.out.println("Make sure you enter a decimal number");
        }
        catch(IOException e)
        {
           System.out.println(e.getMessage());
       }
    }
    return d;
 }

 public static float getFloat()
 {
     float f = 0;
     boolean ok = false;
     while(!ok)
     {
        try
        {
            bytesRead = System.in.read(b);
            s = new String(b,0,bytesRead-1);
            f = (Float.valueOf(s.trim())).floatValue();
            ok = true;
        }
        catch(NumberFormatException e)
        {
            System.out.println("Make sure you enter a decimal number");
        }
        catch(IOException e)
        {
            System.out.println(e.getMessage());
        }
     }
	return f;
  }

  public static char getChar()
  {
     char c = ' ';
     boolean ok = false;
     while(!ok)
     {
        try
        {
           bytesRead = System.in.read(b);
           s = new String(b,0,bytesRead-1);
           if(s.trim().length()!=1)
           {
             System.out.println("Make sure you enter a single character");
           }
           else
           {
                c = s.trim().charAt(0);
                ok = true;
           }
        }
        catch(IOException e)
        {
            System.out.println(e.getMessage());
        }
     }
     return c;
  }


  public static void pause()
  {
     boolean ok = false;
     while(!ok)
     {
         try
         {
             System.in.read(b);
             ok = true;
         }
         catch(IOException e)
         {
              System.out.println(e.getMessage());
         }
     }
  }

  public static void pause(String messageIn)
  {
     boolean ok = false;
     while(!ok)
     {
         try
         {
              System.out.print(messageIn);
              System.in.read(b);
              ok = true;
         }
         catch(IOException e)
        {
              System.out.println(e.getMessage());
        }
    }
  }
}

Ok, I have just used your EasyIn class and your simple program. I can input all 3 numbers without an error, it correctly prints out the sum,product and average of these numbers. You must not be entering an integer.

OUTPUT:
Enter the first number -> 54
Enter the second number -> 34
Enter the third number -> 12
The sum of the three numbers is 100
The product of the three numbers is 22032
The average of the three numbers is 33.0

Enter the first number -> 1
Enter the second number -> 2
Enter the third number -> 3
The sum of the three numbers is 6
The product of the three numbers is 6
The average of the three numbers is 2.0

no I'm entering an integer, but I think the fault lies in the way java is setup on my computer, perhaps I'ved installed it wrong, but in saying that, I've re-installed everythin twice

no I'm entering an integer, but I think the fault lies in the way java is setup on my computer, perhaps I'ved installed it wrong, but in saying that, I've re-installed everythin twice

You said that it's only the 2nd number when it says you need to enter an integer? So it works for the first number you enter? If it works at all then I doubt there is anything wrong with java on your pc.

To install java, just go to http://www.oracle.com/technetwork/java/javase/downloads/index.html...to just get the JDK, click on the first image and for netbeans + JDK etc, click on the 3rd image.

Instead of using your EasyIn class. Try a simple program using the Scanner class and see if it compiles/runs.

import java.util.Scanner;
public class Test{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out,println("Enter a first number");
int first = input.nextInt();
System.out,println("Enter a second number");
int second = input.nextInt();
etc.....



}


}

I've been told about the scanner class before but I prefer using easyin, I'm used to it and it works, but for some reason, this working code doesn't work, so if the codes not at fault, then the only other variables are the IDE or the JDK setup, both of which I've reinstalled twice, installing them according to what the IDE instructs. Its driving me mad.

I've been told about the scanner class before but I prefer using easyin, I'm used to it and it works, but for some reason, this working code doesn't work, so if the codes not at fault, then the only other variables are the IDE or the JDK setup, both of which I've reinstalled twice, installing them according to what the IDE instructs. Its driving me mad.

Wait, so did you try to run/compile that small program I just wrote? and it is not working?
I am failing to understand how you managed to compile and run your program if there is something wrong with jdk or your IDE. Also, the fact that you were able to run it, accept a first number and then fail on the second, would make no sense if your problem lay with those things.

Do you receive an error when trying to run? Please post your exact code, and what you are inputting etc.

I already posted the exact code, the program runs, I enter 2, no problem, I enter 2, the error 'Make sure you enter an integer' appears twice. I know it doesn't make sense, but I've posted all the information for all to see and I still don't know

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.