Page 1 of 1

small help about execution

Posted: Wed Aug 18, 2010 7:29 pm
by Face
I found this question in one of my studding kit..I wanna find the out put of this...I tried with my favorite JAVA editor..It contains errors..

this is the small code

Code: Select all

class EditEx6{
	public static void main(String[] args){
		int a=5,b=4,c=7;
		System.out.printf("%3d%1$d%2$d",a,b,c);
		}
	}
when I compile this.There are no errors...

Code: Select all

>javac EditEx6.java
>Exit code: 0
Then I ran this program with the hope of getting the out put for my question.But Then I got errors or some kind of statements about some errors

This is it...

Code: Select all

>javac EditEx6.java
>Exit code: 0
>java -cp . EditEx6
Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = '$'
	at java.util.Formatter.checkText(Unknown Source)
	at java.util.Formatter.parse(Unknown Source)
	at java.util.Formatter.format(Unknown Source)
	at java.io.PrintStream.format(Unknown Source)
	at java.io.PrintStream.printf(Unknown Source)
	at EditEx6.main(EditEx6.java:4)
>Exit code: 1
can you tell me what is wrong????

Re: small help about execution

Posted: Wed Aug 18, 2010 8:16 pm
by Neo
Try following line.

Code: Select all

System.out.printf("%3d %1d %2d", a, b, c);

Re: small help about execution

Posted: Thu Aug 19, 2010 6:59 pm
by Face
got it..thnkz Neo