import java.io.*; class Mortgage { // Convert double to dollars and cents static String format(double dollars) { String numString = Double.toString(dollars); int dotpos = numString.indexOf(`.'); if (dotpos < 0) // Check if whole number return numString; // Check if excess fraction digits else if (dotpos < numString.length() - 2) return numString.substring(0, dotpos + 3); // `.'+ 2 digits else return numString + "0"; // Assume only 1 fraction digit }