Java Quiz 2

Ace your homework & exams now with Quizwiz!

What is wrong with the following Java statement? System.out.println("Hello, world!);

"

Write one or two statements that declares a char variable c and assigns it the value as a space.

' '

How to represent backslash as a char literal.

'\\'

What is the decimal number of the scientific notation: -2e-3?

-0.002

Which of the two operators, - and /, has higher precedence?

/

What will the following Java statement print?System.out.println((12-9)/3+27%2);

0.22

What is the output of the following statement? int a=5, b=6; System.out.println(a+b+"ends.");

11 ends

What is the result of 29%3?

2

What is wrong with the following Java statement? System.out.println("Hello, world!")

;

What is a logic error?

A bug that occurs with the way a program's logic is structured.

What is an integer literal?

A sequence of digits with or without a leading + or -

What is a syntax error?

An error that occurs when you compile a program, which violates the rules of Java.

What are the four major primitive data types of Java?

Int, double, char, and boolean

What is a runtime error?

It is a logic error that causes a program to stop running.

What are the two broad categories of data types?

Primitive Data Types (only hold one value) and Expressions (returns values)

What is the output of the following statement? int a=8, b=7; System.out.println("The answer is: " + a + b);

The answer is: 15

What is the output of the following program? public class Tricky { public static void main(String[] args){ message1(); message2(); System.out.println("Done with the main method."); }I public static void message1() {I System.out.println("This is message 1."}I public static void message2(){ System.out.println("This is message 2."); message1(); System.out.println("Done with message 2."); } }

This is message 1 This is message 2 Done with the main method.

(True/False) 123. is an integer literal.

True

Write one or two statements that declares a boolean variable flag and assigns it the value true.

boolean flag = true

Write one or two statements that declares a double variable d and assigns it the value 12.5.

double d = 12.5

Write one or two statements that declares an integer variable x and assigns it the value 12.

int x = 12

Does the following code segment have errors? If yes, please point it out and show how to fix it. int a=10.5;

no

What is wrong with the following Java statement? System.ot.println("Hello, world!");

u


Related study sets

ABEKA WORLD HISTORY AND CULTURES APPENDIX QUIZ J

View Set

Define each of the following terms as they relate to monetary and fiscal

View Set

DF242 Exam questions from quizzes + Exam Possible Questions

View Set

Chapter 22: Immune System and the Body's Defense

View Set

Chapter 10: Personality - Exam #4

View Set

HONORS PHYSICAL SCIENCE FINAL EXAM

View Set

Four Requirements for a Binomial Distribution

View Set

Data Collection, Behavior, and Decisions Relias (BCBA)

View Set

EDU 300 - CHAPTER 11 Learners Who Are Deaf or Hard of Hearing

View Set