CIT 130 Midterm

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Which of the following is the correct statement to return to JAVA?

"Java".toUpperCase()

*I DO NOT need the class nor the definition of the main method. There is no need for any import statements. So, save some time. Make sure to define any variables you use.* Write a Java code segment that • Ask the user to enter a number. Assume we have a Scanner object named input already defined. • Use a switch statement that displays ONE if the number is 1 or -1. TWO if the number is -100, and THREE in all other cases.

...

*I am not looking for a complete Java code.* Write Java statements that accomplishes the following. Clearly mark your answer by referring to the question letter. A) Assume you have a variable named num. Use the post-increment operator to add 1 to it. B) Define a variable that can hold any number of characters C) Define a named constant and assign the value -200.86 to it D) Increment the value of the int variable var by 55

...

*This is not meant to be a program that compiles and runs. I only need program segments. DO NOT submit a complete Java file with documentation and other content. Write the statements (NOT an entire program) to:* • Ask the user for the number of students in a classroom. Assume we have a Scanner object input already defined. • Validate the number of students to make sure it's a positive value. NOTE: positive numbers are numbers greater than 0. • For each student, display the message "welcome" followed by a student number that goes from 1 to number of students. For example, if we have 3 students, the output will be: welcome 1 welcome 2 welcome 3

...

Write a *pseudocode(NOT a Java program)* for a program to ask for the width and length of a rectangular table. If the length and the width are both more than 0, calculate and display the area of the table increased by scaling factor of 20. So, if the length is 2 and width is 3, the area will calculated as: 2•3•20.

...

Write the complete definition for the class named Test and the main method for the following requirements: • Define a variable to hold a String • Ask the user for a String. Assume we have a Scanner object named input already defined • Display "Success" if the string entered by the user has a length of 4 and it is equal to "java" • Display "Fail" if the string entered by the user contains the $ symbol

...

The following loop displays _______________. for (int i = 1; i <= 10; i++){ System.out.print(i + " "); i++; }

1 3 5 7 9

What will be printed after the following code segment is executed? int number; for (number = 5; number > 15; number +=3); System.out.print(number + ",");

5,

How many times is the println statement executed? for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) System.out.println(i*j);

9

In programming: the statement money = 200 + 100 Assigns the values of 200 and 100 to the variable named money.

False

Which of the following is not a legitimate statement? Pick the BEST answer.

String x = hello;

What is 1 + 1 + 1 + 1 + 1 == 5?

True

Do the following two statements in (I) and (II) result in the same value in sum? (I): for (int i = 0; i < 10; ++i){ Sum +=i; } (II): for (int i = 0; i < 10; i++){ Sum +=i; }

Yes

The statement System.out.printf("%3.1f", 1234.56); outputs ___________.

1234.6

Which of the following are correct names for variables according to Java naming conventions? There may be more than one correct answer. Pick as many as you like.

1. getRadius 2. circle_radius 3. radius

Which of the following loops prints "Welcome to Java" 10 times? A: for (int count = 1; count <= 10; count++){ System.out.println("Welcome to Java"); } B: for (int count = 0; count < 10; count++){ System.out.println("Welcome to Java"); } C: for (int count = 1; count < 10; count++){ System.out.println("Welcome to Java"); } D: for (int count = 0; count <= 10; count++){ System.out.println("Welcome to Java"); }

AB

Every switch statement must have the default label.

False

Analyze the following fragment: double sum = 0; double d = 0; while (d != 10.0){ d += 0.1; sum = sum +d; }

The program may not stop because of the phenomenon referred to as numerical inaccuracy for operating with floating-point numbers.

What is the output of the following code segment. Assume it compiles and runs. int n; n = 2; while (n > 0){ System.out.print("a"); n--; } System.out.print(n);

aa0

How many times will the following code print "Welcome to Java"? int count = 1; while (count <= 5){ System.out.println("Welcome to Java"); }

an infinite number of times

Which of the following code displays the area of a circle if the radius is a positive non-zero value. Assume the program compiles just fine.

if (radius > 0) System.out.println(radius•radius•3.14159);

Which Scanner class method can read any number entered by the user?

nextDouble()

What is the output of the following code? int x = 0; if (x < 4){ x = x + 1; } System.out.println("x is " +x);

x is 1

What is the output of the following code? int x = 0; while (x <= 4){ x = x + 1; } System.out.println("x is " +x);

x is 5

Assume x is 0 and it has been define as an integer. What is the output of the following statement? if (x > 0) System.out.print("x is greater than 0"); else if (x == 0) System.out.print("x is less than 0"); else System.out.print("x equals 0");

x is less than 0

Suppose x = 100. After the execution of the statement y = --x; What are the values of x and y?

y is 99 and x is 99


Set pelajaran terkait

Mental health (moderate) 15 questions

View Set

SECTION 1 ECONOMICS FINAL REVIEW

View Set

Employment Law: Ch 11 (Wages) & 12(Work Life Conflicts)

View Set

Chapter 2 Employment Laws That Influence Compensation and Benefits

View Set

Chapter 24: Management of Patients with Chronic Pulmonary Disease

View Set

Unit 17 HBiol, Immune System Focus on Antibodies and Vaccines

View Set

Traumatic Injury and Phases of Trauma Care

View Set