user2855719
user2855719

Reputation: 75

I have a simple code which is not working. Cant fix the error "println"

I get a red line under "println". Cant fix this error only..I have tried, but cant make the code work ! any help would be appreciated

public class calculation {
static Double KG;
static Double Price;
static Double Calculate;
static Double Calculate2;
static String i = "5";
static String j = "9";

public static void main(String[] args) {
    System.out.println(Result());
}

private static void Result() {
    KG = ((Double.parseDouble(i) + Double.parseDouble(j) +
          Double.parseDouble(j) + Double.parseDouble(j) + 
          Double.parseDouble(j)) / 10) * (Double.parseDouble(i + j) + 
          Double.parseDouble(i) + Double.parseDouble(i) + Double.parseDouble(i) +
          Double.parseDouble(i));

          Calculate = (Double.parseDouble(i) * 0.6);
          Price = (double) (6 + 5 / 60));
          Calculate2 = (KG / Calculate) - Price;
    }
}

Upvotes: 0

Views: 94

Answers (4)

Rajib Singh
Rajib Singh

Reputation: 21

you are trying to print the results of a method Result() but that method doesn't return anything so println() has nothing to print. Try returning something from Result() and your println should work.

Upvotes: 2

Kick
Kick

Reputation: 4923

Change the return type of the method or write variable which you need to print.

Upvotes: 0

Sujith Surendranathan
Sujith Surendranathan

Reputation: 2579

Since Result returns void and there is no System.out.println(void) method, it will complain.

Upvotes: 0

Andrew Logvinov
Andrew Logvinov

Reputation: 21831

Your Result() method is declared as void, which means it doesn't return anything. As a result, println() is complaining since it needs some input to print.

Probably, you need to modify your program in some way, for example:

public static void main(String[] args) {
  Result(); // calculate values
  System.out.println(KG); // output KG value after it has been calculated
}

Upvotes: 2

Related Questions