0

I'm writing a program for my intro to Java class. I'm getting an error message, and I can't figure out what exactly it's telling me or how to resolve the issue. This is the message:

packageCost.java:17: incompatible types
found   : void
required: java.lang.String
                input = System.out.print("Please enter the weight of " +
                                        ^
packageCost.java:22: incompatible types
found   : void
required: java.lang.String
                input = System.out.print("How many miles is this " +
                                        ^
2 errors

Any help would be appreciated.

0

4 Answers 4

3

System.out.print does not return anything and you are trying to collect its return value in a variable.

2

Your attempting to assign a String to "System.out.print("Please enter..");

System.out.print returns "void" which is not String, thus incompatible types.

It looks like your trying to do console input. You could use a Scanner to do this.

Try something like

Scanner scanner = new Scanner(System.in);
System.out.println("Enter input: ");
String input = scanner.nextLine();

Read about Scanner class, Just google it.

3
  • If I had the rep, -1 for being rude. We all have to start somewhere - stackoverflow is not just for current professionals. At least this isn't a homework question.
    – Tim Joseph
    Sep 20, 2010 at 4:29
  • Was not trying to be rude, that sounded more rude than I intended. I spent three years as a Teaching Assistant, and I'm just saying Programming is a difficult thing to learn without studying and paying attention in class. :)
    – Andy
    Sep 20, 2010 at 13:57
  • 1
    No worries- I'm taking an intro to java class online, so i'm basically given reading material and have to teach myself. We only covered scanner class last week, and i was writing an if else if input program and neglected to add the scanner.
    – Jett
    Sep 20, 2010 at 23:25
2

better:

String input = System.console().readLine("Please enter the ..");
0

The Scanner won't work without declaring at the top of the document:

import java.util.Scanner;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.