EIE3320 Java Programming Basic Quiz
32 Questions
1 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is the purpose of the following Java program?

  • To prompt the user to enter a number for radius
  • To read the radius of a circle and compute its area (correct)
  • To print a message asking for a double value
  • To display the result of a circle's area computation

Which statement is used to create a Scanner object in Java?

  • Scanner(System.in); input = new Scanner;
  • Scanner input = new Scanner(System.in); (correct)
  • Scanner(System.in) input = new Scanner;
  • input = new Scanner(System.in);

What is the purpose of the 'prompt the user to enter a radius' statement in the program?

  • To initialize the value of radius
  • To request the user to input a value for radius (correct)
  • To calculate the area of a circle
  • To display the result of the area computation

What value is used to approximate pi in the program?

<p>3.14159 (B)</p> Signup and view all the answers

In Java, what is the purpose of the 'import java.util.Scanner;' statement in the program?

<p>To import the Scanner class from the java.util package (B)</p> Signup and view all the answers

What does 'System.out.print("Enter a double value: ");' represent in the program?

<p>A message prompting the user to input a double value (C)</p> Signup and view all the answers

What is the correct syntax for declaring a constant in Java?

<p>final int CONSTANT_NAME = 10; (C)</p> Signup and view all the answers

Which naming convention should be used for class names in Java?

<p>Capitalize the first letter of each word (B)</p> Signup and view all the answers

What is the preferred block style for braces in Java?

<p>End-of-line style (B)</p> Signup and view all the answers

How do you get input from input dialog boxes in Java?

<p>Using JOptionPane class (A)</p> Signup and view all the answers

What should you do to obtain a number from the input dialog box in Java?

<p>Use parseInt() method (D)</p> Signup and view all the answers

Which data type is used for constants in Java?

<p>final (A)</p> Signup and view all the answers

What is the correct syntax for declaring a variable in Java?

<p>int variableName = 10; (B)</p> Signup and view all the answers

Which operator is used for shortcut assignment in Java?

<p>+= (A)</p> Signup and view all the answers

What is the correct naming convention for variables and method names in Java?

<p>Capitalize the first letter of each word (D)</p> Signup and view all the answers

How would you convert a string into a number in Java?

<p>.parseInt() method (A)</p> Signup and view all the answers

In Java, what is the purpose of the 'import java.util.Scanner;' statement in the program?

<p>To include the Scanner class from the java.util package (A)</p> Signup and view all the answers

What is the purpose of the 'System.out.print("Enter a number for radius: ");' statement in the program?

<p>To prompt the user to enter a number for the radius (D)</p> Signup and view all the answers

Which keyword is used for declaring a constant variable in Java?

<p>final (B)</p> Signup and view all the answers

What type of input does the 'input.nextDouble();' method expect in the Java program?

<p>Double (C)</p> Signup and view all the answers

Which Java keyword is used to define a reusable block of code that can be called with different arguments?

<p>method (D)</p> Signup and view all the answers

What is the general purpose of the 'ComputeAreaWithConsoleInput' class in the Java program?

<p>To calculate and display the area of a circle based on user input (A)</p> Signup and view all the answers

Which naming convention should be used for variables and method names in Java?

<p>Lowercase for the first word and capitalize the first letter of each subsequent word (C)</p> Signup and view all the answers

What is the correct syntax for declaring a constant in Java?

<p>final datatype CONSTANTNAME = VALUE; (C)</p> Signup and view all the answers

What block style should be used for braces in Java?

<p>End-of-line style (D)</p> Signup and view all the answers

What is the purpose of 'import javax.swing.JOptionPane;' in the program?

<p>To import package for GUI components and input dialog boxes (C)</p> Signup and view all the answers

What is used to obtain the input as a number from a string in Java?

<p>'Integer.parseInt' method (A)</p> Signup and view all the answers

What is the correct naming convention for class names in Java?

<p>Capitalize the first letter of each word in the name (C)</p> Signup and view all the answers

Which operator is used for shortcut assignment in Java?

<p>+= (C)</p> Signup and view all the answers

What is used to approximate pi in Java?

<p>3.14159 (D)</p> Signup and view all the answers

'println' is a method belonging to which class in Java?

<p>'PrintStream' class (A)</p> Signup and view all the answers

'JOptionPane.showInputDialog' is used to get input from which type of dialog box in Java?

<p>'QUESTION_MESSAGE' dialog box (A)</p> Signup and view all the answers
Use Quizgecko on...
Browser
Browser