• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/30

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

30 Cards in this Set

  • Front
  • Back

The purpose of a Java compiler is to:

a. translate class file to source code


b. execute the java program


c. edit the source code


d. translate source code to a class file








Correct answer: d

int x = 8 / 3 - 1; After this statement, x = ____

Correct answer: 1

Which of the following is the Java string concatenation operator?

a. .strcat


b. ++


c. &


d. +








Correct answer: d

Assuming the String variable world holds the value "FLORIDA",

Value of word.substring(1, 3) : LO


Value of word.substring(word.length() - 4) : RIDA

int a = 4, b = 3;


double d = (a + b) / 2


System.out.print( d );




What will be displayed?

Correct answer: 3.0

Write ONE Java statement to display your first and last name on two separate lines, and both in double quotes.




Example: "John"


"Smith"

Correct answer:




System.out.print("\"John\"\n\"Smith\"");

We want to display product names and their prices in a formatted way in a table. In each row of the table, we want to display product names and prices between pound signs (#). For instance, the string variable named product has value "ORANGE". Its price is in a double type variable named price. In each row, allocate 10 characters for product name, and allocate 8 characters for price, and display 2 digits only from the floating part. Make product names left aligned, and prices right aligned.




String name = "ORANGE";


double price = 12.34567


//Below, write ONE line of code only.


//Expected: #ORANGE # 12.34#

Correct answer:




System.out.printf("#%-10s#%8.2f#", name, price);

Write the missing part of the code below, so that for a given word, the program capitalize the first letter, and makes the rest of the letters lowercase. Example; if the name variable is abcDEF, the str becomes Abcdef. ABCD becomes Abcd. goNEN becomes Gonen.




String name = "goNEN";


String str;


// WRITE THIS PART ONLY


System.out.println(str);




Write your code (missing part only) below;

String name = "goNEN";


String str;


str = name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase();


System.out.println(str);

Write a Java statement to access the 7th character in the String variable myString and place it in the char variable c. Below is the method signature that you may use; char charAt(int position)

Correct answer:




char c = myString.charAt(6);

What is the output of this statement?


System.out.printf("#%2#", "HELLO");





a. #HELLO#


b. #HE#


c. # HELLO#


d. Error






Correct answer:


a

What is the output of this statement?


System.out.printf("%1.1f", 98.765);

Correct answer:




98.8

Suppose x = 15.674. The output of the statement System.out.printf("%.2f" , x); is 15.67.




TRUE OR FALSE

Correct answer: TRUE

The new line character is represented as "\n"




TRUE OR FALSE

Correct answer: TRUE

The Scanner class has a method next that allows an entire line of string text to be read.




TRUE OR FALSE

Correct answer: FALSE

Every Java program automatically imports the java.util package.




TRUE OR FALSE

Correct answer: FALSE

What Java package includes the class Scanner?

a. lang


b. swing


c. io


d. util






Correct answer: util

When writing an if statement, you MUST always use curly braces {} to enclose the body of the if.




TRUE OR FALSE

Correct answer: FALSE

When comparing a primitive value to see if it is greater than or equal to another primitive value, you may use either of the following two symbol combinations: >= or =>




TRUE OR FALSE

Correct answer: False

Not including the break statements within a switch statement results in a syntax error (compile-time).




TRUE OR FALSE

Correct answer: False

Any for loop can also be written as a while loop.




TRUE OR FALSE

Correct answer: True

The while loop performs its test before executing its statement.




TRUE OR FALSE

Correct answer: TRUE



Local variables are accessible outside the block in which they are defined.




TRUE OR FALSE

Correct answer: FALSE

Unlike a while loop, the body of a do...while loop executes at least once.




TRUE OR FALSE

TRUE

How many times does the following loop execute:


int[] numbers = {7, 3, 5, 6, 8};


for(int i : numbers) {System.out.println("Hi");}

a. 0


b. 5


c. infinite


d. None (compile error)




Correct answer: b

In Java, _______ is the AND operator.

Correct answer: &&

int k = 9;


String text = "";


if(0 < k && k < 10) {text = "one";}


else if(2 < k && k < 6) {text = "two";}


else if(3 < k && K < 5) {text = "three";}


if (k > 7) {text = "four";}


System.out.println(text);




What will be displayed?

Correct answer: four

The looping mechanism that always executes at least once is the ______ statement.

a. if...else


b. do...while


c. while


d. for






Correct answer: b

int d;


Random generator = new Random();


int d = generator.nextInt(6);




What is the range of d?

a. [0, 1, 2, 3, 4, 5]


b. [0, 1, 2, 3, 4, 5, 6]


c. [-5, -4, -3, -3, -1, 0, 1, 2, 3, 4, 5]


d. [1, 2, 3, 4, 5]




Correct answer: a



Write a for loop to display the numbers below.


50 45 40 35 30 25



public class Forloop{


public static void main(String[] args){


for(int a = 50; a >= 25; a = a - 5){


System.out.print( a + " ")


}


}


}

Write a complete Java class definition for class Employee. Each object of this class has the following; fullname: a String value representing the employee's full name. This must be private. Your class should also have:




A parameterized constructor: Initializes the fullname to the parameter passed.




getFullname method returns the fullname variable. writeOutput: this method displays employee's full name on the screen. In this method you must call getFullname method. Sample output; Employee Full Name: Bilal Gonen




Also write a EmployeeTester class to test your Employee class. In the main method, create an Employee object by using the parameterized constructor. Use your name as the parameter. Then, call the writeOutput method to display the name of employee in the format given above. After running EmployeeTester class, your program must output similar to below; Employee Full Name: Bilal Gonen

public class EmployeeTester{


public static void main(String[] args){


Employee emp2 = new Employee("Joe Code");


emp2.writeOutput();


}


}






Write the Employee class below:




public class Employee


{


private String fullname;




public Employee(String aFullname){


fullname = aFullname;


}




public void writeOutput() {


System.out.println("Employee Full Name: + getFullname());


}




public String getFullname(){


return fullname;


}


}