BPJ Quiz 15+18 A

  1. Make an array of integers whose length is a number $n$ that the user types. Fill it with the perfect squares from $n^2$ down to $1^2$, in that order.

    Example:

     Number?
     10
     [Array contains: {100,81,64,49,36,25,16,9,4,1}]
    

    Starter code:

    public static void main(String[] args) {
        Scanner kb = new Scanner(System.in);
        System.out.println("Number?");
        int n = kb.nextInt();
        // Your code here
    }
    
  2. (Pencil) The Pencil class has a boolean mechanical field and a boolean sharp field. When you make a new pencil, it is always sharp. A pencil has a void write() method which makes non-mechanical pencils get dull. A void sharpen() method makes the pencil sharp. See below for printing out.

    Pencil a = new Pencil(true);  // mechanical pencil
    Pencil b = new Pencil(false); // classic pencil
    System.out.println(a); // "Mechanical pencil"
    System.out.println(b)  // "Sharp classic pencil"
    b.write();
    System.out.println(b)  // "Dull classic pencil"
    
  3. (plus19) Find the sum of all of the elements in the array, except ignore the numbers between the appearance of a 1 and the appearance of the following 9 (inclusive). Every 1 will be followed by at least one 9.

    Example:

    plus19({10,20,30,1,40,50,60,9,70,9}) = 10+20+30+70+9
    
    public static double plus19 (double [] xs)
    
Last modified August 18, 2023: 2022-2023 End State (7352e87)