Java Programming 2

10 Questions | Attempts: 239
Share

SettingsSettingsSettings
Java Programming Quizzes & Trivia

Questions and Answers
  • 1. 

    Which of the following outputs 'I love Java' on the screen?

    • A.

      String IloveJava;

    • B.

      System.out.println ("I love Java");

    • C.

      IloveJava = input.nextLine;

    Correct Answer
    B. System.out.println ("I love Java");
  • 2. 

    How would you declare a variable that will hold a whole number and is called 'mark'?

    • A.

      String mark;

    • B.

      Double mark;

    • C.

      Int mark;

    Correct Answer
    C. Int mark;
  • 3. 

    How would you declare a variable that will hold a single word and is called 'name'? In the same line place the value 'Jane' in this variable.

    • A.

      String name = "Jane";

    • B.

      Jane = name;

    • C.

      "Jane" = name;

    Correct Answer
    A. String name = "Jane";
  • 4. 

    Which of the following creates and assigns an array of 10 marks that will hold whole numbers only?

    • A.

      String[] markList = new String[10];

    • B.

      Int[] markList = new int[10];

    • C.

      Int[10] = markList;

    Correct Answer
    B. Int[] markList = new int[10];
  • 5. 

    Consider the loop below: for (i = 1; i < 11; i++){    System.out.println ("The counter is now reading " + i); }

    • A.

      This loop outputs the numbers 1 to 10

    • B.

      This loop outputs the numbers 1 to 11

    • C.

      This loop outputs the numbers 2 to 10

    Correct Answer
    A. This loop outputs the numbers 1 to 10
  • 6. 

    An array called markList holds ten marks.  Which is the correct code for outputting those marks on the screen?

    • A.

      For ( i = 0; i

    • B.

      For ( i = 0; i

    • C.

      For ( i = 1; i

    Correct Answer
    B. For ( i = 0; i
  • 7. 

    The class Shape has a method called 'findArea'.  shape1 is an object of class Shape.   Which of the following lines calls the method findArea for the object shape1?

    • A.

      Shape1.findArea();

    • B.

      Shape1.Shape.findArea;

    • C.

      Shape.findArea();

    Correct Answer
    A. Shape1.findArea();
  • 8. 

    A programmer has imported the Scanner class into his class and created an object of Scanner called 'input'.  Which of the following reads keyboard input and places it into the integer variable 'length'?

    • A.

      Length = input.nextInt();

    • B.

      Length = Scannerinput;

    • C.

      Input.nextInt.length;

    Correct Answer
    A. Length = input.nextInt();
  • 9. 

    The Math class can be made available to our class by importing it using the line:

    • A.

      Import static java.Math.*;

    • B.

      Import java.lang.Math.*;

    • C.

      Import static java.lang.Math.*;

    Correct Answer
    C. Import static java.lang.Math.*;
  • 10. 

    What is the function of the following line? System.out.println (sqrt(x));

    • A.

      The method sqrt in the Math class is called and so the square of x is output.

    • B.

      The method sqrt in the Math class is called and so the square root of x is output.

    • C.

      The method sqrt in the Math class is called and so the double of x is output.

    Correct Answer
    B. The method sqrt in the Math class is called and so the square root of x is output.

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 15, 2022
    Quiz Edited by
    ProProfs Editorial Team
  • Jun 18, 2012
    Quiz Created by
    Marlenegalea
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.