Joseph Jimenez
Quiz por , criado more than 1 year ago

Introductory JAVA concepts

170
1
0
Joseph Jimenez
Criado por Joseph Jimenez mais de 7 anos atrás
Fechar

JAVA basics

Questão 1 de 68

1

System.out.println or next.Int( ) or close( ) are examples of:

Selecione uma das seguintes:

  • syntax

  • variable

  • method

  • object

Explicação

Questão 2 de 68

1

In the following sample code, how do you best describe the "Scanner":

public class squares {

public static void main(String[] args) {

java.util.Scanner scanner = new java.util.Scanner(System.in);

int num = 0;

System.out.print("Please enter a number: ");
num = scanner.nextInt();

scanner.close();

Selecione uma das seguintes:

  • statement

  • method

  • object

  • argument

Explicação

Questão 3 de 68

1

In the sample code below, what best describes num ?

public static void main(String[] args) {

java.util.Scanner scanner = new java.util.Scanner(System.in);

int num = 0;
int result = 0;

System.out.print("Please enter a number: ");
num = scanner.nextInt();

result = num * num;

scanner.close();
}

}

Selecione uma das seguintes:

  • string

  • statement

  • variable

  • object

Explicação

Questão 4 de 68

1

All is (are) true of pseudocode except:

Selecione uma das seguintes:

  • comments that are understood by people

  • recognized by the compiler

  • a tool programmers use when creating a model of the program

Explicação

Questão 5 de 68

1

Preencha os espaços em branco para completar o texto.

string literals.
– char literals are enclosed in quotes.
- literals are enclosed in double quotes

Explicação

Questão 6 de 68

1

How do you assign a variable?

Selecione uma das seguintes:

  • use an = sign

  • In order to store a value in a variable, an assignment statement must be used

  • Both are correct

Explicação

Questão 7 de 68

1

Preencha os espaços em branco para completar o texto.

This program asks to simply input a word or "string" and the output is the first character of the word (so an input of agents, the program's output is "a")

java.util.Scanner scanner =
("Enter a character: ");
char inputChar =
System.out.println("You have entered: "+inputChar);

Explicação

Questão 8 de 68

1

What is wrong with the following code:
System.out.println("The quick brown fox" + "jumped over the \n" "slow moving hen.");

Selecione uma das seguintes:

  • there are extra " " between \n and slow

  • use of the "+" is not correct

  • nothing is wrong with the code and should print "jump over the \n slow moving hen

Explicação

Questão 9 de 68

1

which is NOT a valid statement

Selecione uma das seguintes:

  • */comment 3/*

  • //comment 1

  • /**comment 4*/

Explicação

Questão 10 de 68

1

Which of the following will fix the code below:

final int x = 22, y = 4;

y += x;

System.out.println("x = " + x + ", y = " + y);

Selecione uma das seguintes:

  • change y+=x; to y = y + x

  • remove "final" because this makes the "int x" a constant

  • nothing is wrong with the code

Explicação

Questão 11 de 68

1

How can you output quotation marks around green ("green") in the System.out.println() method:

Selecione uma das seguintes:

  • System.out.println("\green\")

  • System.out.println(\"green\")

  • System.out.println(\\"green"\\)

Explicação

Questão 12 de 68

1

Preencha os espaços em branco para completar o texto.

In the JAVA language, fill in what best coincides with the given term
Classes:
: camelCase
: CAPS_UNDERSCORE

Explicação

Questão 13 de 68

1

How do you define a method?

Selecione uma das seguintes:

  • public.java.util.scanner = scanner()

  • public returnType methodName(arg1Type, arg2Type,...) {
    }

  • import java util.*;

Explicação

Questão 14 de 68

1

In the following code, System.out.println(num) is an example of:

double num = 5.4;

System.out.println(num);

num = 0.0;

Selecione uma das seguintes:

  • class method

  • value returning method

  • void method

Explicação

Questão 15 de 68

1

If method A calls method B, and method B calls method C, and method C calls method D, when method D finishes, what happens?

Selecione uma das seguintes:

  • the program terminates

  • control is returned to C

  • control is returned to A

Explicação

Questão 16 de 68

1

When an argument is passed to a method:

Selecione uma das seguintes:

  • values may not be passed to the method

  • its value is copied into the method's parameter variable

  • its value may not be changed within the call method

Explicação

Questão 17 de 68

1

In the following code, Integer.parseInt(str), is an example of:

int num;

string str = "555";

num = Integer.parseInt(str) + 5;

Selecione uma das seguintes:

  • void method

  • value returning method

  • complex method

Explicação

Questão 18 de 68

1

If chr is a character variable, which of the following if statements is written correctly?

Selecione uma das seguintes:

  • if(char = 'a')

  • if (char == 'a')

  • If(char=="a")

Explicação

Questão 19 de 68

1

Preencha o espaço em branco para completar o texto.

works like this: If the expression on the left side of the && operator is false, the expression the right side will not be checked.

Explicação

Questão 20 de 68

1

To do a case insensitive compare which of the following could be used to test the equality of two strings, str1 and str2?

Selecione uma das seguintes:

  • str1.equalsIgnoreCase(str2)

  • str1.compareToIgnoreCase(str2) == 0

  • Both

Explicação

Questão 21 de 68

1

What would be the value of x after the following statements were executed?

int x = 10;

switch (x)

{

case 10:

x += 15;

case 12:

x -= 5;

break;

default:

x *= 3;

}

Selecione uma das seguintes:

  • 20

  • 30

  • 15

Explicação

Questão 22 de 68

1

What will be displayed to the screen with the following statements?

System.out.print("$%,.4f", 4452.34246);

Selecione uma das seguintes:

  • $4,452.34246

  • 4452.34246

Explicação

Questão 23 de 68

1

What will be the value of x after the following code is executed? If the code has any kind of syntax error, please type in the answer “error”.
int x = 10
if (x>5) {
x /= 10;
}
if (x<5) {
x += 5;
}
if (x > 10) {
x -=4;
}
else {
x+=4;
}

Selecione uma das seguintes:

  • 10

  • 0

  • 12

Explicação

Questão 24 de 68

1

An if statement's alternative path is implemented with _______.

Selecione uma das seguintes:

  • switch

  • else

  • if

Explicação

Questão 25 de 68

1

The part of a method that is a collection of statements that are performed when the method is executed is called the method _______.

Selecione uma das seguintes:

  • body

  • arguments

Explicação

Questão 26 de 68

1

When a primitive data type argument is passed to a method, it is passed by _______.

Selecione uma das seguintes:

  • reference

  • value

Explicação

Questão 27 de 68

1

When an object, such as a String, is passed as an argument, it is passed by

Selecione uma das seguintes:

  • value

  • reference

Explicação

Questão 28 de 68

1

What will be the values of x and y as a result of the following code?

int x = 25, y = 8;

x += y++;

Selecione uma das seguintes:

  • x = 33; y = 9

  • x=34; y = 9

Explicação

Questão 29 de 68

1

What will be printed after the following code is executed?

for (int number = 5; number <= 15; number +=3)

System.out.print(number + ", ");

Selecione uma das seguintes:

  • 5, 8, 11, 14, 17

  • 5, 8, 11, 14

Explicação

Questão 30 de 68

1

UML diagrams does contain

Selecione uma das seguintes:

  • field names

  • object names

Explicação

Questão 31 de 68

1

Unified Modeling Language which is used in object oriented software engineering.

Selecione uma das seguintes:

  • using the private access specifier on the class methods

  • using the private access specifier on the class fields

Explicação

Questão 32 de 68

1

You should not define a class field that is dependent upon the values of other class fields:

Selecione uma das seguintes:

  • in order to avoid having stale data

  • in order to keep it current

Explicação

Questão 33 de 68

1

Instance methods do not have this key word in their headers:

Selecione uma das seguintes:

  • public

  • protected

  • static

Explicação

Questão 34 de 68

1

It is common practice to use a ________ variable as a size declarator

Selecione uma das seguintes:

  • reference

  • final

Explicação

Questão 35 de 68

1

What will be the value of x[8] after the following code has been executed?

final int SUB = 12;

int[] x = new int[SUB];

int y = 100;

for(int i = 0; i < SUB; i++)

{

x[i] = y;

y += 10;

}

Selecione uma das seguintes:

  • 200

  • 170

  • 180

Explicação

Questão 36 de 68

1

Java performs ________, which means that it does not allow a statement to use a subscript that is outside the range of valid subscripts for the array.

Selecione uma das seguintes:

  • array bounds checking

  • scope resolution binding

Explicação

Questão 37 de 68

1

What will be the results of the following code?

final int ARRAY_SIZE = 5;

double[] x = new double[ARRAY_SIZE];

for(int i = 1; i <= ARRAY_SIZE; i++)

{

x[i] = 10.0;

}

Selecione uma das seguintes:

  • compilation error will occur

  • An error will occur when the program runs

Explicação

Questão 38 de 68

1

What would be the results of the following code?

int[] x = { 55, 33, 88, 22, 99,

11, 44, 66, 77 };

int a = 10;

if(x[2] > x[5])

a = 5;

else

a = 8;

Selecione uma das seguintes:

  • a=5

  • a=8

Explicação

Questão 39 de 68

1

What would be the results of the following code?

int[] array1 = new int[25];

… // Code that will put values in array1

int value = array1[0];

for (int a = 1; a < array1.length; a++)

{

if (array1[a] < value)

value = array1[a];

}

Selecione uma das seguintes:

  • Value contains the highest value in array1.

  • Value contains the lowest value in array1

Explicação

Questão 40 de 68

1

What do you normally use with a partially-filled array?

Selecione uma das seguintes:

  • An accompanying integer value that holds the number of items stored in the array

  • An accumulator

Explicação

Questão 41 de 68

1

To return an array of long values from a method, use this as the return type for the method.

Selecione uma das seguintes:

  • long[ARRAY_SIZE]

  • long[]

Explicação

Questão 42 de 68

1

In order to do a binary search on an array:

Selecione uma das seguintes:

  • the array must first be sorted in ascending order

  • there are no requirements

Explicação

Questão 43 de 68

1

What is the value of scores[2][3] in the following array?

int [] [] scores = { {88, 80, 79, 92}, {75, 84, 93, 80},

{98, 95, 92, 94}, {91, 84, 88, 96} };

Selecione uma das seguintes:

  • 93

  • 94

Explicação

Questão 44 de 68

1

The part of a method that is a collection of statements that are performed when the method is executed is called

Selecione uma das seguintes:

  • argument

  • method body

Explicação

Questão 45 de 68

1

An array has a/an __________ size

Selecione uma das seguintes:

  • fixed

  • dynamic

  • both answers are acceptable

Explicação

Questão 46 de 68

1

An ArrayList has a fixed or dynamic size

Selecione uma das seguintes:

  • False

  • True (either or statement is true)

Explicação

Questão 47 de 68

1

When trying to access an element of an array, Java performs array _____ checking to make sure the subscript of the element exists

Selecione uma das seguintes:

  • method

  • bound

Explicação

Questão 48 de 68

1

Given an array variable with the name kiwi, what is the code to get the amount of elements in kiwi?

Selecione uma das seguintes:

  • kiwi.length

  • kiwi.length;

Explicação

Questão 49 de 68

1

Given an ArrayList variable with the name kiwi, what is the code to get the amount of elements in kiwi?

Selecione uma das seguintes:

  • kiwi.size;

  • kiwi.size()

Explicação

Questão 50 de 68

1

Given a String variable with the name kiwi, what is the code to get the amount of characters in kiwi?

Selecione uma das seguintes:

  • kiwi.length();

  • kiwi.size();

Explicação

Questão 51 de 68

1

Classes have _______ which store data

Selecione uma das seguintes:

  • objects

  • fields

Explicação

Questão 52 de 68

1

What is the term used for the character that separates tokens?

Selecione uma das seguintes:

  • tokenizer

  • delimiter

Explicação

Questão 53 de 68

1

What will be the value of x after the following code is executed?

int x, y = 2, z = 3;
x = (++y)*(++z);

Selecione uma das seguintes:

  • error, x is undefined

  • 12 (since ++y becomes 3 and ++z becomes 4)

Explicação

Questão 54 de 68

1

How many times will the following do-while loop be executed?

int x = 5;
do
{ x*=2;} while (x > 10)

Selecione uma das seguintes:

  • 10

  • 1

Explicação

Questão 55 de 68

1

What will be the value of x after the following code is executed? If the code has any kind of syntax error, please type in the answer "error".
int x = 1;
while (x++ < 10) {
x++;
}

Selecione uma das seguintes:

  • 9

  • 12

Explicação

Questão 56 de 68

1

How many times will the following for loop be executed?

for (int count = 1; count <= 7; count += 3) {System.out.println("Java is great!!!");}

Selecione uma das seguintes:

  • two

  • three

Explicação

Questão 57 de 68

1

What will the following code output to the console?

int [ ] integers = new int [5];
System.out.println(integers[0]);

Selecione uma das seguintes:

  • zero since this is the default value for int

  • one

Explicação

Questão 58 de 68

1

What will the following code output to the console?
ArrayList<Integer> integers = new ArrayList<>(5);
System.out.println(integers.get(0));

Selecione uma das seguintes:

  • 0

  • error since new array list is not defined

Explicação

Questão 59 de 68

1

What is the output?

ArrayList<Integer> integers = new ArrayList<>();
integers.add(5);
integers.add(7);
integers.add(1,18);
integers.remove(0);
System.out.println(integers.get(0));

Selecione uma das seguintes:

  • 1

  • 18

Explicação

Questão 60 de 68

1

What's the output?

ArrayList<String> strings = new ArrayList<>();
strings.add("hi");
strings.add("bye");
strings.add("howdy");
strings.remove(0);
System.out.println(strings.get(2));

Selecione uma das seguintes:

  • howdy

  • error

Explicação

Questão 61 de 68

1

What is the output?

int[ ] integers = {1,2,3,4,5};
for (int i = 0; i< integers.length; i++) {
integers [i]++;
}
System.out.println(integers[3]);

Selecione uma das seguintes:

  • five

  • four

Explicação

Questão 62 de 68

1

What is the output?

int[]integers = new int[10];
final int AMOUNT_OF_RUNS = 20;
final int ADD_ME = 5;

for (int i = 0; i < AMOUNT_OF_RUNS; i++) {
integers[i] += ADD_ME;
}
System.out.println(integers[3]);

Selecione uma das seguintes:

  • error because it is asking to run an amount of 20 times when an array is only 10 long

  • 10

Explicação

Questão 63 de 68

1

What is the output?

int [ ] integers = new int [10];
final int ADD_ME = 5;

for (int i = 0; i< integers.length; i++) {
integers [i] += ADD_ME*1;
}
System.out.println(integers[4]);

Selecione uma das seguintes:

  • error

  • 20

Explicação

Questão 64 de 68

1

What is the output?

int [ ] [ ] integers = { { 14, 5, 21}, {34, 54}, {3, 6, 7}};
int total = 0;
for (int row = 0; row<integers.length; row++) {
for (int col = 0; col<integers[0].length; col++) {
total += integers[row][col];
}
}
System.out.println(total);

Selecione uma das seguintes:

  • Error since this is a ragged array

  • 54

Explicação

Questão 65 de 68

1

What is the output?
int [ ] [ ] integers = { { 14, 5, 21}, {34, 54}, {3, 6, 7}};
int mysteryVariable = 0;
for (int row = 0; row<integers.length; row++) {
for (int col = 0; col<integers[row].length; col++) {
mysteryVariable++;
}
}
System.out.println(mysteryVariable);

Selecione uma das seguintes:

  • error

  • 8

Explicação

Questão 66 de 68

1

what is the output?

int [] [] integers = {{14,5,21{, {34, 54}, {3,6,7}};
int mysteryVariableOne = integers [0][0];
int mysteryVariableTwo = integers [0][0];
for (int row = 0; row < integers.length; row++) {
for (int col = 0; col <integes[row].length; col++) {
if (mysteryVariableOne < integers[row][col]) {
mysteryVariableOne = integers[row][col];
}
if (mysteryVariableTwo> integers[row][col]) {
mysterVariableTwo = integers[row][col];
}}}

System.out.println(myseryVariableOne - mysteryVariableTwo);

Selecione uma das seguintes:

  • 51 (since 54 is the highest, and 3 is the lowest then 54 - 3 = 51)

  • error

Explicação

Questão 67 de 68

1

Output?

static ArrayList<String> listOfStrings;

public static void main (String[ ] args) {
String [ ] strings = {"D", "Z", "G", "P", "M" };
for (String s : strings)
listOfStrings.add(s);
System.out.println(listOfStrings.get(2));
}

Selecione uma das seguintes:

  • error

  • G

Explicação

Questão 68 de 68

1

Output?

static ArrayList<String> listOfStrings;

public static void main (String[ ] args) {
String [ ] strings = {"D", "Z", "G", "P", "M" };
ArrayList<String> listOfStrings = new ArrayList<>();
for (int i = strings.length-1; i>0; i--) {
listOfStrings.add(strings[i] + strings[i-1]);
System.out.println(listOfStrings.get(2));

Selecione uma das seguintes:

  • Error

  • GZ

  • ZD

Explicação