Java Reference
In-Depth Information
root1= (
b
Math. sqrt(delta))/(2.0
a);
root2= (
b+Math. sqrt(delta))/(2.0
a);
System . out . println ( root1 ) ;
System . out . println ( root2 ) ;
System . out . println ( "Let us check the roots:" );
System . out . println (a
root1+c) ;
System . out . println (a root2 root2+b root2+c) ;
}
}
root1
root1+b
Note that for this particular initialization, we have delta>0 . Otherwise, there
are imaginary roots, and the program will crash in the Math.sqrt function.
1.8 Basics of Java input/output (I/O)
In this section, we quickly review the elementary instructions for reading or
writing on the console. We will then see how to redirect input/output from/to
files.
1.8.1 Computing does not mean displaying
In Java, one needs to explicitly display results on the console to read them back.
Printing the results on the console is one way to retrieve or export the results
of programs. This is very different from most mathematical symbolic systems
such as Maple R
, 10 which computes and displays results at once. For example,
in Maple computing 2 + 2 will not only compute the sum but also display the
result 4:
>2+2;
4
This is one frequent source of confusion for beginners who have had prior
“programming” experience with such mathematical packages. Remember that
in Java, we need to explicitly display results.
1.8.1.1 Displaying results on the console. To display messages on the console
in Java, one invokes either System.out.println for writing a string message
with a return line, or System.out.print for writing a message without the
return line. One can also display integers, reals or strings. Since it is quite
cumbersome to write several System.out.print[ln] at a row like:
10 http://www.maplesoft.com/
 
 
Search WWH ::




Custom Search