简体   繁体   中英

Getting multiple errors compiling Java code in Eclipse

I'm new to programming, and I'm using Eclipse to make some easy programs like calculators and vote counting. (Don't mind the language, it's Portuguese and i'm from Brazil.)

So as you can see in the image with "Questão1.java." Class opened compiles perfectly, and the "Questão2.java" shows quite a lot of errors, and I have absolutely no idea what it means.

This one is giving a lot of errors:

这个给出了很多错误

This one compiles perfectly, no errors and results as expected:

这个编译完美,没有错误和预期的结果。

Thanks everyone for answering, i found out the error and it was indeed the "printf"...and also i'll remember to never post codes as images next time, again thank you guys.

The problem is that you use printf() instead of print() or println() .

printf() adds formatting to whatever you are trying to print, and the String that determines how your output should be formatted uses characters like % , which you also use in the class that throws errors.

The error

Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = ' '
    at [and so on...]
    at Questao2_Lista[bla bla bla].main(Questao2.java:18)

can be read in the following way:

The first line defines what kind of exception was thrown, in this instance it is an "UnknownFormatConversionException".

The lines below it are called a "stacktrace", that show where exactly the exception was thrown and the "way" it got propagated up the call-stack.

It looks like this is the only error, I can't see any of the other errors you talked about so I guess you just assumed that every line was a separate error?

The problem with "Questão2.java" is the System.out.printf statement. The statement has a '%' which is a special character. % is used as a preceding character for a place holder

Eg: %d in the string will be replaced with a number passed as an argument.

int lines =10;
System.out.printf ("There are %d lines", lines);

Will come as:

There are 10 lines 

If its just a print statement Use System.out.println instead of System.out.printf

尝试在 Questão2.java 的第 18 行中使用System.out.print()System.out.println()代替System.out.printf()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM