CSE 110 Midterm Exam Study Guide

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

When using data type float, what is needed to make a java literal a float?

The "f." So 5.25f and 5f would be acceptable.

How do you know when a java literal is using the data type char?

When a single character enclosed in a single quote. So '\n' and '5' would be acceptable.

How do you declare a variable of type boolean in Java?

boolean a = false; boolean a;

Given the following declaration: String s = "Apples and bananas are yummy."; Evaluate the expression: s.substring(2, 4)

"pl"

Given the following declaration: String s = "Apples and bananas are yummy."; Evaluate the expression: s.substring(1, 3)

"pp"

Given the following declaration: String s = "Go_Sun_Devils"; Evaluate the expression: s.charAt(3)

'S'

Given two String variables, s1 and s2, to determine if they are the same length, which of the following conditions would you use?

(s1.equals(s2))

What characters cannot be used in java identifiers?

- A valid identifier must have characters [A-Z] or [a-z] or numbers [0-9], and underscore(_) or a dollar sign ($). for example, @javatpoint is not a valid identifier because it contains a special character which is @. - There should not be any space in an identifier. For example, java tpoint is an invalid identifier. - An identifier should not contain a number at the starting. For example, 123javatpoint is an invalid identifier. - An identifier should be of length 4-15 letters only. However, there is no limit on its length. But, it is good to follow the standard conventions. - We can't use the Java reserved keywords as an identifier such as int, float, double, char, etc. For example, int double is an invalid identifier in Java. - An identifier should not be any query language keywords such as SELECT, FROM, COUNT, DELETE, etc.

Given the following declaration: String s = "Bananas and apples are yummy."; s.indexOf("A")

-1 (not found)

When the following expression is evaluated, the result will be what Java data type? 3f + 5

Double

When the following expression is evaluated, the result will be what Java data type? 7.0 / 3f

Double

Which of the following would be the best data type for a variable to store a person's height in meters?

Float

Given the following declaration: String s = "7 birds and 12 cats"; s.length()

19

Given the following int (integer) variables - a = 11 b = 37 c = 3 d = 5 Evaluate the expression: a + b % c * d

3

What will be the output of this code? int x = 13; int y = 3; int a = y; y = x; x = a; System.out.print(x);

3

What will be the output of this code? int x = 2; int y = 10; x = y + 1; y = x - 1; x = x + 1; y = y - 1; x = x - y; System.out.print(x);

3

What will this small program output? class Main { private static void foo() { int x = 15; } private static int x = 3; public static void main(String[] args) {foo(); System.out.println(x);} }

3

What are the Java primitive data types?

Byte Short Int Long Float Double Boolean Char

Which of the following would be the best data type for a variable to store the number of passengers on an airplane?

Int

Given the following declarations: String s1 = "a banana"; String s2 = "banana"; Evaluate the expression: s1.compareTo(s2) < 0

True

Given the following declarations: String s1 = "carrot"; String s2 = "carrot"; Evaluate the expression: s2.equals(s1)

True

Write a line of Java code that will declare a double variable named x that is initialized to the value 90.24.

double x = 90.24;


संबंधित स्टडी सेट्स

American History, HIST 207A, Chapter 3 (Part 1) | Mid-Term 1301, Chapter 3 (True or False) | Mid-Term 1301

View Set

Chapter 10 - Macroeconomics Quiz

View Set

Illinois State - Executive Branch

View Set

Ch 37 Classical Eclecticism Quiz

View Set

Mastering A and P Chapter 12 Part 1

View Set

Identifying phrases, what are phrases

View Set

DISCRETE MATH 2030 - FINAL TEST 4 REVIEW (W/ TESTS 1 - 3 ONLY)

View Set

Chapter 45: Nursing Care of the Child With an Alteration in Tissue Integrity/Integumentary Disorder

View Set

PD BIO MID II - (Ch 5-7 & Assign #4) finalized

View Set