int i, j, k, m;
// some Java statements are omitted that assign values to i, j, k, & l.
// Your Java statement goes here
Create a single Java statement that assigns new values to i,
j, k, and m as follows (in the order indicated):
int i, j, k, m;Solution:
// some Java statements are omitted that assign value to i, j, k, & m.
k %= j *= ++i + m--;
2. Give Java statements for computing the sum of the odd numbers squared from 1 to 2001. That is, 1 + 9 + 25 + ... + 2001*2001.
3. Given the applet skeleton below, fill in the paint method so that it renders the following picture:
In the picture above, painting is inset 40 pixels from the left and the top. Each black square has an edge length of edg; there are num such squares on the diagonal and anti-diagonal.
public class test1 extends Applet
implements ActionListener, MouseListener
{
int num = 5, edg =
20, x, y;
boolean clicked = false;
Label
numL = new Label("Number:"),
edgL = new Label("Edge length:");
TextField numT
= new TextField("5", 2),
edgT = new TextField("20", 2);
public void init() {
add(numL); add(numT);
add(edgL); add(edgT);
numT.addActionListener(this);
edgT.addActionListener(this);
addMouseListener(this);
}
public void paint(Graphics
g)
{
//
Your code to paint the red and black squares goes here
//
Your code to process the mouse release goes here (see Question 4)
}
public void actionPerformed(ActionEvent
e) {
num = Integer.parseInt(numT.getText());
edg = Integer.parseInt(edgT.getText());
repaint();
}
public void mousePressed(MouseEvent
e) {}
public void mouseClicked(MouseEvent
e) {}
public void mouseReleased(MouseEvent
e) {
x = e.getX();
y = e.getY();
clicked = true;
repaint();
}
public void mouseEntered(MouseEvent
e) {}
public void mouseExited(MouseEvent
e) {}
}