Practice problem #1

What will be printed?

System.out.println("toothpicks".substring(5));
System.out.println("toothpicks".indexOf('t'));
System.out.println("toothpicks".indexOf('t', 2));
System.out.println("toothpicks".charAt(5));
System.out.println("toothpicks".length());
System.out.println(3/4);
System.out.println(23/4);

 

 

Practice problem #2

Write a Doubler class with the following:

  • A constructor that takes a number as its input.
    The number can have digits after the decimal.
  • A method called next() that works like this:
  • Doubler d = new Doubler(2.5);
    System.out.println(d.next());  // prints 2.5
    System.out.println(d.next());  // prints 5.0
    System.out.println(d.next());  // prints 10.0
    System.out.println(d.next());  // prints 20.0
    System.out.println(d.next());  // prints 40.0
    System.out.println(d.next());  // prints 80.0
    
    Etc.