Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java prinitng var's issue, sorry for posting same again

Tags:

java

so i cant run even such a simple code suddenly:"

 public class Test {
public static void main (String [] args)
{
    int i=6;
    System.out.println("this is i: %d" ,i);
}
}

didnt work with printf either. same goes for format...etc.

the error im getting is this: Exception in thread "main" java.lang.Error: Unresolved compilation problem:

The method println(int) in the type PrintStream is not applicable
for the arguments (String, int) at examples.Test.main(Test.java:7)

I dont know what went wrong with the compiler... should i just re instal the eclipse?

like image 545
user3443891 Avatar asked Sep 18 '26 14:09

user3443891


1 Answers

System.out.println accepts only one argument (of any primitive type, String, Object or array of char) and can't print formatted text. You should use printf instead:

System.out.printf("this is i: %d\r\n" ,i);
like image 126
nikis Avatar answered Sep 20 '26 04:09

nikis