Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
Tentamen (uitwerkingen)

CSC 1350 Exam -2 Questions and Answers

Beoordeling
-
Verkocht
-
Pagina's
27
Cijfer
A+
Geüpload op
22-01-2025
Geschreven in
2024/2025

CSC 1350 Exam -2 Questions and Answers

Instelling
Vak

Voorbeeld van de inhoud

CSC 1350 Exam #2 Questions and
Answers

What are the two parts of an if statement?
a) An increment and a return value
b) An increment and a body
c) A check and an increment
d) A condition and a body - Correct Answers-d) A condition and a body

Which of the following statements is true about the if statement?

a) The if and else blocks should always be included within curly braces
b) The else block is optional
c) The if statement can have only one condition that evaluates to an integer value
d) The if block is optional - Correct Answers-b) The else blocks is optional

The following code snippet contains an error. What is the error?
if (cost > 100); {
cost = cost -10;
}
System.out.println("Discount cost: " + cost);
a) Logical error: use of an uninitialized variable
b) Logical error: if statement has do-nothing statement after if condition
c) Syntax error (won't compile)
d) Logical error: assignment statement does not show equality - Correct Answers-b)
Logical error: if statement has do-nothing statement after if condition

What is the output of the following code snippet?
int num = 100;
if (num > 100); {
num = num - 10;
}
System.out.println(num);
a) 100
b) 101
c) 90
d) 99 - Correct Answers-c) 90

The operator !> stands for ____________________.
a) Not greater than
b) This is not an operator in Java.

,c) Not less than
d) Not equal to - Correct Answers-b) This is not an operator in Java.

What is the output of the following code snippet?
int x = 50;
if (x > 100) {
x++;
}
else {
x--;
}
System.out.println(x);
a) 50
b) 51
c) 49
d) 52 - Correct Answers-c) 49

Assuming that the user enters 60 as the input, what is the output after running the
following code snippet?
int num = 0;
Scanner in = new Scanner(System.in);
System.out.print("Enter a number: ");
num = in.nextInt();
if (num < 10) {
System.out.println("Too small!");
}
else if (num < 50) {
System.out.println("Intermediate!");
}
else if (num < 100) {
System.out.println("High!");
}
else {
System.out.println("Too high!");
}
a) Too high!
b) Intermediate!
c) High!
d) Too small! - Correct Answers-c) High!

What is the output after running the following code snippet?
int number = 600;
if (number < 200) {
System.out.println("Low spender");
}
else if ( number < 500) {

, System.out.println("Spending in moderation");
}
else if (number < 1000) {
System.out.println("Above average!");
}
else {
System.out.println("High Roller!");
} - Correct Answers-b) Above average!

An if statement inside another if statement is called a ______________________.
a) break statement
b) syntax error, since that is not permitted in Java
c) switch statement
d) nested if statement - Correct Answers-d) nested if statement

Assuming that a user enters 10, 20, and 30 as input values one after another, separated
by spaces, what is the output of the following code snippet?
int num1 = 0;
int num2 = 0;
int num3 = 0;
Scanner in = new Scanner(System.in);
System.out.print("Enter a number: ");
num1 = in.nextInt();
System.out.print("Enter a number: ");
num2 = in.nextInt();
System.out.print("Enter a number: ");
num3 = in.nextInt();
if (num1 > num2) {
if (num1 > num3) {
system.out.println(num1);
}
else {
System.out.println(num3);
}
}
else {
if (num2 > num3) {
System.out.println(num2);
}
else {
System.out.println(num3);
}
}
a) 0
b) 10
c) 20

Geschreven voor

Vak

Documentinformatie

Geüpload op
22 januari 2025
Aantal pagina's
27
Geschreven in
2024/2025
Type
Tentamen (uitwerkingen)
Bevat
Vragen en antwoorden

Onderwerpen

$12.49
Krijg toegang tot het volledige document:

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kun je een ander document kiezen. Je kunt het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF

Maak kennis met de verkoper
Seller avatar
EXAMHAVEN

Ook beschikbaar in voordeelbundel

Maak kennis met de verkoper

Seller avatar
EXAMHAVEN Havard School
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
4
Lid sinds
1 jaar
Aantal volgers
2
Documenten
1615
Laatst verkocht
4 maanden geleden

0.0

0 beoordelingen

5
0
4
0
3
0
2
0
1
0

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Bezig met je bronvermelding?

Maak nauwkeurige citaten in APA, MLA en Harvard met onze gratis bronnengenerator.

Bezig met je bronvermelding?

Veelgestelde vragen