Variable incompatible with Strings

Using the Java SDK with TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
wikiwiki
Posts: 2
Joined: Wed Jan 28, 2009 11:40 pm

Variable incompatible with Strings

Post by wikiwiki »

Hi all,
I'm taking a java class in college and running a few programs that the book gives me to test out my software, and i'm running into a couple errors. I installed JDK-6 and TextPad 5.
The program i'm running is
import java.util.Scanner;

public class EggBasket2
{
public static void main(String[] args)
{
int numberOfBaskets, eggsPerBasket, totalEggs;

Scanner keyboard = new Scanner(System.in);
System.out.println("Enter the number of eggs in each basket:");
eggsPerBasket = keyboard.nextInt();
System.out.println("Enter the number of baskets:");
numberOfBaskets = keyboard.nextInt();

totalEggs = numberOfBaskets * eggsPerBasket;

System.out.println("If you have");
System.out.println(eggsPerBasket = " eggs per basket and");
System.out.println(numberOfBaskets = " baskets, then");
System.out.println("the total number of eggs is " + totalEggs);

System.out.println("Now we take two eggs out of each basket.");

eggsPerBasket = eggsPerBasket - 2;
totalEggs = numberOfBaskets * eggsPerBasket;

System.out.println("You now have");
System.out.println(eggsPerBasket = " eggs per basket and");
System.out.println(numberOfBaskets = " baskets.");
System.out.println("The new total number of eggs is " + totalEggs);
}
}

It compiles just fine but when i try to run it i get errors saying
incompatible types found : java.lang.String
required: int
System.out.println(eggsPerBasket = "eggs per basket and");

It gives me errors on each line written in that format.
Any help you guys could give me would be great, i have an assignment due in a couple days and need to get stuff like this fixed as soon as possible.
wikiwiki
Posts: 2
Joined: Wed Jan 28, 2009 11:40 pm

Post by wikiwiki »

Nevermind, i got it. Forgot to capitalize = so it wasn't the right command.
Post Reply