| | |
printf and three string arguments
![]() |
Hi all, I hope you are well. I am trying to compile a java file using terminal in Ubuntu, but I am getting the following error message:
As you can see, I am passing three String arguments to the printf method, which, as far as I can tell from the API is perfectly legal as this would correspond to the object varargs printf method.
Interestingly, this compiles & executes fine in NetBeans (on the same machine, so same JDK version). Please can someone tell me if I have missed something here? Many thanks.
•
•
•
•
1. ERROR in StringComparisons.java (at line 20)
System.out.printf("String a = %s String b = %s \n", a,b);
•
•
•
•
printf
public PrintStream printf(String format,
Object... args)
A convenience method to write a formatted string to this output stream using the specified format string and arguments.
Last edited by majestic0110; Oct 16th, 2009 at 1:24 pm.
If you have a quality, be proud of it and let it define you. Add it to the world!
If you got your answer, please mark the thread as Solved. It saves time when people are looking to contribute threads or for answers!
If you got your answer, please mark the thread as Solved. It saves time when people are looking to contribute threads or for answers!
•
•
Join Date: Nov 2008
Posts: 332
Reputation:
Solved Threads: 53
0
#2 Oct 16th, 2009
bug?
test:
compile one test at the same time
post result
test:
Java Syntax (Toggle Plain Text)
String format = "String a = %s String b = %s \n"; System.out.printf(format, a, b); System.out.printf("String a + %s String b + %s \n", a, b); System.out.printf(new String("String a = %s String b = %s \n"), a, b); System.out.printf("String a " + "=" + " %s String b " + "=" + " %s \n", a, b); System.out.printf("String a " + '=' + " %s String b " + '=' + " %s \n", a, b);
post result
0
#3 Oct 18th, 2009
Hi quuba, thanks for the reply. Having tried that, I still get the same compilation error at the command line, although it works fine in NetBeans. Seems very odd!
If you have a quality, be proud of it and let it define you. Add it to the world!
If you got your answer, please mark the thread as Solved. It saves time when people are looking to contribute threads or for answers!
If you got your answer, please mark the thread as Solved. It saves time when people are looking to contribute threads or for answers!
0
#5 Oct 18th, 2009
They all do quuba lol i.e the ones with >= 3 arg's to printf
Last edited by majestic0110; Oct 18th, 2009 at 8:49 pm.
If you have a quality, be proud of it and let it define you. Add it to the world!
If you got your answer, please mark the thread as Solved. It saves time when people are looking to contribute threads or for answers!
If you got your answer, please mark the thread as Solved. It saves time when people are looking to contribute threads or for answers!
•
•
Join Date: Nov 2008
Posts: 332
Reputation:
Solved Threads: 53
0
#6 Oct 19th, 2009
Compile with additional javac options to obtain more info:
? odd.
check also from command line version of java
if 1.5 - bad
if >1.5 - ok.
http://java.sun.com/docs/books/tutor...berformat.html
Java Syntax (Toggle Plain Text)
javac -help javac -version javac -g -verbose StringComparisons.java pause
check also from command line version of java
if 1.5 - bad
if >1.5 - ok.
http://java.sun.com/docs/books/tutor...berformat.html
•
•
•
•
Here is a basic example:
int i = 461012;
System.out.format("The value of i is: %d%n", i);
The %d specifies that the single variable is a decimal integer. The %n is a platform-independent newline character.
Last edited by quuba; Oct 19th, 2009 at 11:50 am.
![]() |
Similar Threads
- Acessing indefinte arguments for a function? (C++)
- Counting an inputted letter in an inputted string using getchar() (C)
- command line arguments help (C)
- Reverse string arrays (C)
- Simply question: How do I return a string from a function (C)
- Sane way of dynamically allocating arrays beyond declaration. (C)
- hellp please (Java)
- Array Values not found in Methods (Java)
- Program Compiles fine, but error upon Running (Java)
- Reversive Array/Integer (C)
Other Threads in the Java Forum
- Previous Thread: How to resolve an indirect html url?
- Next Thread: Client - Server Application
| Thread Tools | Search this Thread |
.net age amd apple applet array automation avatar bluegene bsd c++ canonical centos chips class code component database debian dell design desktop development distributions dos eclipse economy energy enterprise error fedora firefox fractal game gnome google gui hardware html ibm ibm.news image intelibm java javafx javascript jetbrains knoppix linux mac medicine memory method microsoft mobile mobileapplication mysql netbeans netbook netbooks newbie news novell openoffice opensource os pc php problem program programming project ps3 python recession redhat russia security service set shuttleworth slackware software source sun supercomputer supercomputing suse swing technology terminal tree trends ubuntu unix virtualization web windows working x86







