QUESTION 54Given:1. public class LineUp {2. public static void main(String[] args) {3. double d = 12.345;4. // insert code here5. }6. }Which code fragment, inserted at line 4, produces the output | 12.345|?A. System.out.printf("|%7d| \n", d);B. System.out.printf("|%7f| \n", d);C. System.out.printf("|%3.7d| \n", d);D. System.out.printf("|%3.7f| \n", d);E. System.out.printf("|%7.3d| \n", d);F. System.out.printf("|%7.3f| \n", d);Solution : F
plus imformation
A. | Exception in thread "main" java.util.IllegalFormatConversionException: d != java.lang.Double
at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:3999)
at java.util.Formatter$FormatSpecifier.printInteger(Formatter.java:2709)
at java.util.Formatter$FormatSpecifier.print(Formatter.java:2661)
at java.util.Formatter.format(Formatter.java:2433)
at java.io.PrintStream.format(PrintStream.java:920)
at java.io.PrintStream.printf(PrintStream.java:821)
at LineUp.main(Main.java:4)
B. |12.345000|
C. Exception in thread "main" java.util.IllegalFormatPrecisionException: 7
at java.util.Formatter$FormatSpecifier.checkInteger(Formatter.java:2892)
at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2643)
at java.util.Formatter.parse(Formatter.java:2480)
at java.util.Formatter.format(Formatter.java:2414)
at java.io.PrintStream.format(PrintStream.java:920)
at java.io.PrintStream.printf(PrintStream.java:821)
at LineUp.main(Main.java:4)
D. |12.3450000|
E. Exception in thread "main" java.util.IllegalFormatPrecisionException: 3
at java.util.Formatter$FormatSpecifier.checkInteger(Formatter.java:2892)
at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2643)
at java.util.Formatter.parse(Formatter.java:2480)
at java.util.Formatter.format(Formatter.java:2414)
at java.io.PrintStream.format(PrintStream.java:920)
at java.io.PrintStream.printf(PrintStream.java:821)
at LineUp.main(Main.java:4)
F. | 12.345|
'자격증 > OCJP_ExamB' 카테고리의 다른 글
QUESTION 56 (0) | 2018.07.13 |
---|---|
QUESTION 55 (0) | 2018.07.13 |
QUESTION 53 (0) | 2018.07.13 |
QUESTION 52 (0) | 2018.07.13 |
QUESTION 51 (0) | 2018.07.13 |
#IT #먹방 #전자기기 #일상
#개발 #일상