23.07.2013 Views

Java IO.pdf - Nguyen Dang Binh

Java IO.pdf - Nguyen Dang Binh

Java IO.pdf - Nguyen Dang Binh

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

scanf("%d", &x);<br />

In C++, that line would become:<br />

cin >> x;<br />

In Pascal:<br />

READLN (X);<br />

In Fortran:<br />

READ 2, X<br />

2 FORMAT (F5.1)<br />

<strong>Java</strong> I/O<br />

Similarly, formatting numeric strings for output tends to be mixed up with writing the string<br />

to the screen. For instance, consider the simple task of writing the double variable salary<br />

with two decimal digits of precision. In C, you'd write this:<br />

printf("%.2d", salary);<br />

In C++:<br />

cout.precision(2);<br />

cout

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!