printf and three string arguments

Reply

Join Date: Oct 2007
Posts: 1,293
Reputation: majestic0110 has a spectacular aura about majestic0110 has a spectacular aura about majestic0110 has a spectacular aura about 
Solved Threads: 67
majestic0110's Avatar
majestic0110 majestic0110 is offline Offline
Nearly a Posting Virtuoso

printf and three string arguments

 
0
  #1
Oct 16th, 2009
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:

1. ERROR in StringComparisons.java (at line 20)
System.out.printf("String a = %s String b = %s \n", a,b);
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.

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.
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.
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!
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 332
Reputation: quuba is on a distinguished road 
Solved Threads: 53
quuba quuba is offline Offline
Posting Whiz
 
0
  #2
Oct 16th, 2009
bug?
test:
  1. String format = "String a = %s String b = %s \n";
  2. System.out.printf(format, a, b);
  3. System.out.printf("String a + %s String b + %s \n", a, b);
  4. System.out.printf(new String("String a = %s String b = %s \n"), a, b);
  5. System.out.printf("String a " + "=" + " %s String b " + "=" + " %s \n", a, b);
  6. System.out.printf("String a " + '=' + " %s String b " + '=' + " %s \n", a, b);
compile one test at the same time
post result
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,293
Reputation: majestic0110 has a spectacular aura about majestic0110 has a spectacular aura about majestic0110 has a spectacular aura about 
Solved Threads: 67
majestic0110's Avatar
majestic0110 majestic0110 is offline Offline
Nearly a Posting Virtuoso
 
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!
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 332
Reputation: quuba is on a distinguished road 
Solved Threads: 53
quuba quuba is offline Offline
Posting Whiz
 
0
  #4
Oct 18th, 2009
Which one of 2,..,6 lines in my post #2 gives you compilation error at the command line?
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,293
Reputation: majestic0110 has a spectacular aura about majestic0110 has a spectacular aura about majestic0110 has a spectacular aura about 
Solved Threads: 67
majestic0110's Avatar
majestic0110 majestic0110 is offline Offline
Nearly a Posting Virtuoso
 
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!
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 332
Reputation: quuba is on a distinguished road 
Solved Threads: 53
quuba quuba is offline Offline
Posting Whiz
 
0
  #6
Oct 19th, 2009
Compile with additional javac options to obtain more info:
  1. javac -help
  2.  
  3. javac -version
  4.  
  5. javac -g -verbose StringComparisons.java
  6.  
  7. pause
? 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
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.
Reply With Quote Quick reply to this message  
Reply


Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC