Home > Net >  error: no suitable method found for println(String,double) System.out.println
error: no suitable method found for println(String,double) System.out.println

Time:11-24

java:19: error: no suitable method found for println(String,double)
   System.out.println("The health is %.2f",kiloliters);
             ^
    method PrintStream.println() is not applicable
      (actual and formal argument lists differ in length)
    method PrintStream.println(boolean) is not applicable
      (actual and formal argument lists differ in length)
    method PrintStream.println(char) is not applicable
      (actual and formal argument lists differ in length)
    method PrintStream.println(int) is not applicable
      (actual and formal argument lists differ in length)
    method PrintStream.println(long) is not applicable
      (actual and formal argument lists differ in length)
    method PrintStream.println(float) is not applicable
      (actual and formal argument lists differ in length)
    method PrintStream.println(double) is not applicable
      (actual and formal argument lists differ in length)
    method PrintStream.println(char[]) is not applicable
      (actual and formal argument lists differ in length)
    method PrintStream.println(String) is not applicable
      (actual and formal argument lists differ in length)
    method PrintStream.println(Object) is not applicable
      (actual and formal argument lists differ in length)
2 errors
if(kiloliters > 1000 && kiloliters < 10000){ //test if the inputted number is in between 1000 and 10000
   kiloliters = (kiloliters   150)/140;
   System.out.println("The health is %.2f",kiloliters);

CodePudding user response:

Java println() is the original "print text" method. You can use it like this:

System.out.println("The health is " kiloliters);

printf() is a newer addition to Java; it allows "formatted printing" like C, C and Java. You can use it like this:

System.out.printf("The health is %.2f",kiloliters);

Yet another option is String.format():

System.out.println(String.format("The health is %.2f",kiloliters));

CodePudding user response:

You should use System.out.format() instead:

System.out.format("The health is %.2f\n",kiloliters);
  •  Tags:  
  • java
  • Related