0% found this document useful (0 votes)
1K views5 pages

Quiz 5

The document discusses String comparison in Java and provides examples to illustrate the difference between using the == operator versus the equals() method. It shows that == compares the object references, not the values, while equals() performs a value comparison. Multiple code snippets are provided with explanations of the output.

Uploaded by

ZULE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views5 pages

Quiz 5

The document discusses String comparison in Java and provides examples to illustrate the difference between using the == operator versus the equals() method. It shows that == compares the object references, not the values, while equals() performs a value comparison. Multiple code snippets are provided with explanations of the output.

Uploaded by

ZULE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

A String comparison with == compares the Strings’ locations in memory and not the content of the String.

Usporedba nizova sa == uspoređuje lokacije nizova u memoriji, a ne sadržaj niza.

True

What is the output?


Što je izlaz?

public static void main(String[] args) {


   String name = "Java";
   String language = "Programming";
   String fullName = name + language;
   boolean test = fullName.equals(name + language);
   System.out.println(test);
}

True

What is the output?


Što je izlaz?
public static void main(String[] args) {
   int age = 43;
   if (age == 43){
     System.out.print("Bob is 43 ");
   }
   if (age == 50){
     System.out.print("Bob is 50 ");
   }
}

Bob is 43

The equal sign (=) is used to make an assignment, whereas the == sign merely makes a comparison
and returns a boolean.

Znak jednakosti (=) koristi se za dodjelu, dok znak == samo čini usporedbu i vraća booleovu vrijednost.

True

Which operator is used to test if both sides of a boolean expression are equal?

Koji se operator koristi za testiranje jesu li obje strane booleovog izraza jednake?

==

Which three are conditional statements?

Koja su tri uvjetna iskaza?

if/else statement

if statement

switch statement
Which are used in a boolean expression?

Koji se koriste u logičkom izrazu?

Operators

Vatiables

A customer is eligible for a discount based on certain criteria. Under what conditions does “You qualify
for a discount” print? (Hint: There may be more than one correct answer)
Kupac ima pravo na popust na temelju određenih kriterija. Pod kojim uvjetima se ispisuje "Kvalificirate
se za popust"? (Savjet: Može biti više od jednog točnog odgovora)
int purchase;
int rewardPoints;
if (purchase >= 2000 || rewardPoints >= 4000) {
   System.out.println("You qualify for discount");
}

When purchase is 4000 and rewardPoints is 2000

When purchase is 2000 regardless of the value of rewardPoints

What is the result?


Što je rezultat?
public static void main(String[] args) {
   int point = 10;
   String s = (point == 1 ? "point" : "points");
   System.out.println("I scored " +point +" " +s );
}

I scored 10 points

In Java, an if statement can be nested inside another if statement.

U Javi, if izraz može biti ugniježđen unutar drugog if naredbe.

True

In the AND (&&) test, if the first expression on the left hand side is false, then there is no need to
evaluate the second statement.

U AND (&&) testu, ako je prvi izraz s lijeve strane netočan, onda nema potrebe za procjenom druge izjave.

True
What is the output?
Što je izlaz?
public static void main(String args[]) {
   char grade ='E';
   if (grade == 'A') {
      System.out.println("Excellent performer");
   }else if (grade == 'B') {
      System.out.println("Good Performer");
   }else if (grade == 'C') {
   System.out.println("Average Performer");
   }else {
      System.out.println("Below Average Performer");
   }
}

Below Average Performer

What is the output?


Što je izlaz?
char grade = 'A';
switch (grade) {
   case 'A':
      System.out.println("Congratulations!");    case 'B':
      System.out.println("Good work");
   case 'C':
      System.out.println("Average");
   case 'D':
      System.out.println("Barely passing");
   case 'F':
      System.out.println("Failed");
}

Congratulations! Good Work Average Barely Passing Failed

Which two statements are true about the default statement?

Koje su dvije tvrdnje točne za zadanu izjavu?

When the input does not match any of the cases, the default statement is executed.

The default statement is optional in switch statement.

A break statement causes control to transfer to the end of the switch statement.

Naredba break uzrokuje prijenos kontrole na kraj naredbe switch.

True

What are the possible values of a boolean data type in Java?

Koje su moguće vrijednosti booleovog tipa podataka u Javi?

True/false
An if/else statement is used when you need to choose between two alternatives.

Naredba if/else koristi se kada trebate birati između dvije alternative.

True

The switch statement is a more efficient way to write code when dealing with a large range of
unknown values

Naredba switch je učinkovitiji način za pisanje koda kada se radi s velikim rasponom nepoznatih vrijednosti

False

Which two are not logical operators?

Koja dva nisu logički operatori?

An employee is eligible for a bonus based on certain criteria.


Under what conditions does “Eligible for a bonus” print?
Zaposlenik ima pravo na bonus na temelju određenih kriterija.

Pod kojim uvjetima se ispisuje "Ispunjava pravo na bonus"?


int rating;
int experience;
if (rating > 1 && experience == 5) {
   System.out.println (“Eligible for a bonus”);
}

5 experience and 2 or more rating

In the OR (||) test, if the first expression on the left hand side is true then there is no need to evaluate the second
statement.

U testu ILI (||), ako je prvi izraz s lijeve strane istinit, nema potrebe za procjenom druge izjave.

True

In a boolean expression which uses the && operator, what would make this expression evaluate to
true?

U booleovskom izrazu koji koristi && operator, što bi učinilo da ovaj izraz procijeni na istinito?

boolean x = (firstCondition && secondCondition);

If both the first condition and second condition are true

How should Strings be compared?

Kako treba uspoređivati Stringove?

The equals() method


What is the output?
Što je izlaz?
public static void main(String args[]) {
   char ch ='c';
   switch(ch) {
     case 'a':
     case 'e':
     case 'i':
     case 'o':
     case 'u':
       System.out.println("Vowels");
       break;
     default:
       System.out.println("Consonants");
   }
}

Consonants

Which two of the following data types can be used in a switch statement?

Koje dvije od sljedećih vrsta podataka mogu se koristiti u naredbi switch?

String

int

You might also like