Programming and Problem Solving with Java

(やまだぃちぅ) #1
627

Container dataPane; // Content pane
dataFrame = newJFrame();
dataPane = dataFrame.getContentPane();
dataFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
dataFrame.setSize( 450 , 75 );
dataPane.setLayout(newGridLayout( 2 , 1 ));
decimal = newDecimalFormat("#0.0");
integral = new DecimalFormat("#0");
String ch;
int n;
doubley;

ch = "A";
dataPane.add(newJLabel(ch));
ch = "B";
dataPane.add(newJLabel(ch));
n = 413 ;
y = 21.8;
dataPane.add(newJLabel(integral.format(n) + " is the value of n"));
dataPane.add(newJLabel(decimal.format(y) + " is the value of y"));
dataFrame.setVisible(true);
}
}

11.Given that xis a doublevariable and x= 2314.3827, show the output of each pair
of statements below. Use a to indicate each blank.
a.num = newDecimalFormat("#0.00");
out.add(newJLabel("x is "+ num.format(x)));
b.num = newDecimalFormat("#,##0.00");
out.add(newJLabel("x is "+ num.format(x)));
c. num = newDecimalFormat("0.0");
out.add(newJLabel("x is "+ num.format(x)));
d.num = newDecimalFormat("#,##0.000");
out.add(newJLabel("x is "+ num.format(x)));

Free download pdf