How to align? Come in help me...thx

my output is like this:

class Alignment

{

public String left(String s, int len)

{

String temp = new String(s);

for (int i=0;i<len-s.length();i++)

{

temp = temp + " ";

}

return temp;

}

public String right(String s, int len)

{

String temp = new String(s);

for (int i=0;i<len-s.length();i++)

{

temp = " " + temp;

}

return temp;

}

}

ser[0].setSERVICE("Cut");

ser[1].setSERVICE("Shampoo");

ser[2].setSERVICE("Manicure");

ser[3].setSERVICE("Style");

ser[4].setSERVICE("Permanent");

ser[5].setSERVICE("Trim");

pri[0].setPRICE(8.00);

pri[1].setPRICE(4.00);

pri[2].setPRICE(18.00);

pri[3].setPRICE(48.00);

pri[4].setPRICE(18.00);

pri[5].setPRICE(6.00);

avg[0].setAVGMIN(15);

avg[1].setAVGMIN(10);

avg[2].setAVGMIN(30);

avg[3].setAVGMIN(55);

avg[4].setAVGMIN(35);

avg[5].setAVGMIN(5);

/*This is my source code*/

System.out.println("ServicePrice($) Time (Minute)");

System.out.println("======= ======== =============");

for (int i=0;i<=5;i++)

{

System.out.println(align.left(ser.getSERVICE(),19)+pri.getPRICE()+""+avg.getAVGMIN());

}

Output:

ServicePriceTime (Minute)

=========================

Cut8.015

Shampoo4.010

Manicure14.0 30

Style 48.0 55

.....6.05>

[1508 byte] By [Suqina] at [2007-11-27 10:29:42]
# 1

Use the String.format() static method(s).

sabre150a at 2007-7-28 17:59:01 > top of Java-index,Java Essentials,Java Programming...
# 2

Can you show the example for me?

because me not very understand what your meaning...thx alot

Suqina at 2007-7-28 17:59:01 > top of Java-index,Java Essentials,Java Programming...
# 3

http://java.sun.com/docs/books/tutorial/java/data/strings.html (at the end of the page)

and/or:

http://www.google.nl/search?hl=en&safe=off&q=String.format+example+java&btnG=Search

prometheuzza at 2007-7-28 17:59:01 > top of Java-index,Java Essentials,Java Programming...
# 4

String fs;

fs = String.format("%-10s"+"%lf"+"%d",ser.getSERVICE(),pri.getPRICE(),avg.getAVGMIN());

System.out.print(fs);

i write like this but it got error....

C:\TestService.java:74: cannot resolve symbol

symbol : method format (java.lang.String,java.lang.String,double,int)

location: class java.lang.String

fs = String.format("%-10s"+"%lf"+"%d",ser.getSERVICE(),pri.getPRICE(),avg.getAVGMIN());

Message was edited by:

Suqin

Suqina at 2007-7-28 17:59:01 > top of Java-index,Java Essentials,Java Programming...
# 5

What is being displayed if you type the following command in your prompt/shell: javac -version

?

prometheuzza at 2007-7-28 17:59:01 > top of Java-index,Java Essentials,Java Programming...
# 6

i use this JCreator 3.50 LE

Message was edited by:

Suqin

Suqina at 2007-7-28 17:59:01 > top of Java-index,Java Essentials,Java Programming...
# 7

> i use this JCreator 3.50 LE

>

> Message was edited by:

> Suqin

You are probably using an older JDK (inside your IDE). The String.format(...) method was added in Java 1.5+.

In short: upgrade your JDK.

prometheuzza at 2007-7-28 17:59:01 > top of Java-index,Java Essentials,Java Programming...
# 8

Can tell me where to dl the new JDK file?

but this is my assignement and my sch using this JDK =.=...

Message was edited by:

Suqin

Suqina at 2007-7-28 17:59:01 > top of Java-index,Java Essentials,Java Programming...
# 9

> Can tell me where to dl the new JDK file?

If you have searched for it and can't find it, I'll tell you where to download it. So, have you searched for it already?

> but this is my assignement and my sch using this JDK

> =.=...

>

> Message was edited by:

> Suqin

Well, then you can't make use of the String.format(...) method.

prometheuzza at 2007-7-28 17:59:01 > top of Java-index,Java Essentials,Java Programming...
# 10

The newest JDK is what?

if no use the String.format() method , got other method can use?

Suqina at 2007-7-28 17:59:01 > top of Java-index,Java Essentials,Java Programming...
# 11

> if no use the String.format() method , got other

> method can use?

Create a method that accepts a String and desired width and pads the String (left or right) with spaces to the desired width and then returns the new String.

sabre150a at 2007-7-28 17:59:01 > top of Java-index,Java Essentials,Java Programming...
# 12

if i have the double and integer var?

also can use the same method?

Suqina at 2007-7-28 17:59:01 > top of Java-index,Java Essentials,Java Programming...
# 13

> if i have the double and integer var?

>

> also can use the same method?

Yes - you first convert the double and integer to a String using your desired approach and then use the new method.

sabre150a at 2007-7-28 17:59:01 > top of Java-index,Java Essentials,Java Programming...
# 14

ok...i will go try !!

and thx u all reply me....if still got prolem hope u all can help!! ^^

Suqina at 2007-7-28 17:59:01 > top of Java-index,Java Essentials,Java Programming...