- Jun 18, 2004
- 101
- 0
- 0
Can someone please help with the below stated code? I am trying to learn Java by myself and these were the two questions that were at the end of the chapter and I have no clue what to fill in and how to do it? Please help, thanks.
1. Fill in the blanks in the following progam that contains an integer n from the command-line argment and displays n! (where n! is the product of all numbers from 1 to n, pronounced "n factorial"):
public class NFactorial
{
_________________________ main __________________________
{
int n = Integer.parseInt( ________ );
int k;
long fact = 1;
for ( k = 2; _________________ )
{
____________________ ;
}
system.out.println(n + "! = " + _____________________ ) ;
}
}
_____________________________________________________________________________________________________________________________________
2. Write a class RedDisk derived from JApplet; make it show a red disk in the middle of a white rectangle (like the Japanese flag). Make sure your applet is scalable.
Hints:
You can get the current dimentions of the applet's content pane as follows:
Container c = getContentPane( );
int w = c.getWidth( );
int h = c.getHeight( );
You can use the following method to draw a disk (a filled circle) of adius r with the center at (x, y):
private void drawDisk (graphics g, int x, int y, int r)
{
g.fillOval (x - r, y - r, 2*r, 2*r);
}