String s = "exam";
boolean okay = false;
if ( s.substring(1,2).equals("e") )
okay = true;
if ( okay )
System.out.println("Okay!");
else
System.out.println("Not Okay!");
int year = 1900;
boolean leap = (year % 4 == 0) && !(year % 100 == 0);
leap = leap || (year % 400 == 0);
if ( leap )
System.out.println("Leap!");
else
System.out.println("Not Leap!");
import ccj.*;
public class Mystery
{ public static void main(String[] args)
{ int x = 12345;
if ( myst(x) % 3 == 0 )
System.out.println("Divisible!");
else
System.out.println("Indivisible!");
}
public static int myst(int x)
{ if ( x < 10 )
return x;
return ( (x%10) + myst(x/10) );
}
}
import ccj.*;
public class MysteryApplet extends GraphicsApplet
{ public void run()
{ Point p1 = new Point(-5,-5);
Circle c1 = new Circle(p1, 4);
c1.draw();
p1.move(7,7);
p1.draw();
Line l1 = new Line(p1, new Point(0,0));
l1.draw();
}
}
.)
public static double hare(double x) { return 2 * hatter(x/2); }
public static double hatter(double x) { return x * alice(x); }
public static double alice (double x) { return mouse(x) - 1 ; }
public static double mouse(double x) { return x*x - x; }
1 6 3 8 4(Hint: Use recursion.)