Would you like to react to this message? Create an account in a few clicks or log in to continue.

Formated I/O

Go down

 Formated I/O Empty Formated I/O

ตั้งหัวข้อ  Admin Thu May 22, 2008 10:41 am

Formatter()

Formatter(Appendable buf)

Formatter(Appendable buf,Locale loc)

Formatter(Sring filename)
Throws FileNotFoundException, UnsuportedEncodingExcepion

Formatter(File outF)
Throws FileNotFoundException

Formatter(OutputStream outStrm)
Admin
Admin
Admin

จำนวนข้อความ : 112
Registration date : 18/05/2008

http://chawban.chocoforum.com

ขึ้นไปข้างบน Go down

 Formated I/O Empty Re: Formated I/O

ตั้งหัวข้อ  Admin Thu May 22, 2008 11:05 am

package printf;

import java.util.Formatter;
import static java.lang.System.out;
public class exam1 {


public static void main(String [] args) {

Formatter fmt = new Formatter();
out.println(fmt.format("Formatting %s is easy %d %f", "ʴ", 10, 98.6));

}

}




šѹ
Formatting ʴ is easy 10 98.600000


แก้ไขล่าสุดโดย Admin เมื่อ Thu May 22, 2008 11:16 am, ทั้งหมด 1 ครั้ง
Admin
Admin
Admin

จำนวนข้อความ : 112
Registration date : 18/05/2008

http://chawban.chocoforum.com

ขึ้นไปข้างบน Go down

 Formated I/O Empty Re: Formated I/O

ตั้งหัวข้อ  Admin Thu May 22, 2008 11:05 am

Formatter fmt = new Formatter();
out.println(fmt.format("Formatting %s is easy %d %f", "ʴ", 98.6, 10));


Exception in thread "main" java.util.IllegalFormatConversionException: d != java.lang.Double
at java.util.Formatter$FormatSpecifier.failConversion(Unknown Source)
at java.util.Formatter$FormatSpecifier.printInteger(Unknown Source)
at java.util.Formatter$FormatSpecifier.print(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at printf.exam1.main(exam1.java:11)
Admin
Admin
Admin

จำนวนข้อความ : 112
Registration date : 18/05/2008

http://chawban.chocoforum.com

ขึ้นไปข้างบน Go down

 Formated I/O Empty Re: Formated I/O

ตั้งหัวข้อ  Admin Thu May 22, 2008 11:37 am

Formatter fmt = new Formatter();

fmt.format("Formatting %S is easy %d %d", "ʴ", 10, (int)98.6);

System.out.println(fmt);
Admin
Admin
Admin

จำนวนข้อความ : 112
Registration date : 18/05/2008

http://chawban.chocoforum.com

ขึ้นไปข้างบน Go down

 Formated I/O Empty Re: Formated I/O

ตั้งหัวข้อ  Admin Thu May 22, 2008 12:02 pm

float xx =123456.789987f;
fmt.format("OLD %f \nNEW %.2f ", xx,xx);
out.println(fmt);

OLD 123456.789063
NEW 123456.79 //ѹлѴ

<hr size="2" width="100%">
float xx =1234.56712f;
out.println("Original : "+xx);
fmt.format("OLD %f \nNEW[.2] %.2f \nNEW[.3] %.3f ", xx,xx,xx);
out.println(fmt);
------------------------------
Original : 1234.5671
OLD 1234.567139
NEW[.2] 1234.57 // Ѵеǵ令 7
NEW[.3] 1234.567 // Ѵŧеǵ令 1

5

Original : 1234.5651 // 1 ѧ 5 Ѵ
NEW[.2] 1234.57

Original : 1234.565
// Ţͷ 5 Ѵŧ
NEW[.2] 1234.56

Admin
Admin
Admin

จำนวนข้อความ : 112
Registration date : 18/05/2008

http://chawban.chocoforum.com

ขึ้นไปข้างบน Go down

 Formated I/O Empty Re: Formated I/O

ตั้งหัวข้อ  Admin Thu May 22, 2008 12:18 pm

fmt.format("NEW[.2] |%10.2f| ",xx);
out.println(fmt);

Original : 1234.5651
NEW[.2] | 1234.57|
Admin
Admin
Admin

จำนวนข้อความ : 112
Registration date : 18/05/2008

http://chawban.chocoforum.com

ขึ้นไปข้างบน Go down

ขึ้นไปข้างบน


 
Permissions in this forum:
คุณไม่สามารถพิมพ์ตอบ