1. create a String?
2. concatenate Strings?
3. add newlines, tabs, and double quotes to Strings?
4. determine the number of characters in a String?
5. convert a String to a numeric value?
6. convert a number to a String?
What methods do we use to output Strings to the monitor?
How can we format double values?
import java.text.*;
/**
* Illustrate formatting output
* @author Suzanne Balik, 5 Feb 2003
*/
public class Output {
public static void main(String[] args) {
double value = 2.0/3.0;
System.out.println("value = " + value);
DecimalFormat twoDigits = new DecimalFormat("0.00");
System.out.println("value = " + twoDigits.format(value));
String formattedValue = twoDigits.format(value);
System.out.println("value = " + formattedValue);
}
}
/* PROGRAM OUTPUT
csc% java Output
value = 0.6666666666666666
value = 0.67
value = 0.67
*/