Week 10 – Quiz!!

1 / 22

# Week 10 – Quiz!! - PowerPoint PPT Presentation

Week 10 – Quiz!!. 1 st Round. Spot the bug! Answers : 1 – Loop never finishes 2 – Won’t repeat while loop 3 – Infinite loop 4 – Array out of bounds exception. Spot the bug -1 . boolean santa=true; while(santa=true) santa=false; -&gt;Loop never finishes. Spot the bug - 2.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about 'Week 10 – Quiz!!' - saki

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### Week 10 – Quiz!!

1st Round

Spot the bug!

1 – Loop never finishes

2 – Won’t repeat while loop

3 – Infinite loop

4 – Array out of bounds exception

Spot the bug -1

boolean santa=true;

while(santa=true)

santa=false;

->Loop never finishes

Spot the bug - 2

String reindeer;

do {

System.out.print("Any more?”);

} while(reindeer=="y");

-> Won’t repeat while loop

Spot the bug - 3

int i = 0;

while (i < 10)

System.out.println(i);

i++;

System.out.println(“Finished”);

-> Infinite loop

Spot the bug - 4

String astrNames[]=

{"Dasher","Donner","Blitzen"};

For (int i=1;i<=astrNames.length;i++){

System.out.println(astrNames[i]);

}

-> Array out of bounds exception

2nd Round

Match the Error!

• array dimension missing
• java.lang.NullPointerException
• <identifier> expected
• ArrayOutOfBoundsExeption
• illegal start of expression
• variable s might not have been initialized
• '(' or '[' expected
Match the Error - 1

public class Sleigh

{

public static void main (String args[]) {

String s = null;

System.out.println(s.length());

}

}

Match the Error - 2

public class Sleigh

{

public static void main (String args[]) {

String s;

System.out.println(s.length());

}

}

Match the Error - 3

public class Sleigh

{

public static void main (String args[]) {

String s = null;

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

s+=i;

}

System.out.println(s.length());

}

}

Match the Error - 4

public class Sleigh

{

public static void main (String args[]) {

String s = new String;

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

s+=i;

System.out.println(s.length());

}

}

Match the Error - 5

public class Sleigh

{

public static void main (String args[]) {

String s[] = new String[];

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

s[i]+=i;

System.out.println(s);

}

}

Match the Error - 6

public class Sleigh

{

public static void main (String args[]) {

String s[] = new String({"Dasher","Donner","Blitzen"});

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

s[i]+=i;

System.out.println(s.length());

}

}

Match the Error - 7

public class Sleigh

{

public static void main (String args[]) {

String s[] = new String[10];

for (int i = 1; i <= s.length; i++)

s[i]=i+"";

System.out.println(s[0]);

}

}

• 1 – B
• 2 – F
• 3 – C
• 4 – G
• 5 – A
• 6 – E
• 7 - D
Match the Error - 1

public class Sleigh

{

public static void main (String args[]) {

String s = null;

System.out.println(s.length());

}

}

at Sleigh.main(Sleigh.java:5)

Match the Error - 2

public class Sleigh

{

public static void main (String args[]) {

String s;

System.out.println(s.length());

}

}

Sleigh.java:5: variable s might not have been initialized

System.out.println(s.length());

^

1 error

Match the Error - 3

public class Sleigh

{

public static void main (String args[]) {

String s = null;

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

s+=i;

}

System.out.println(s.length());

}

}

Sleigh.java:8: <identifier> expected

System.out.println(s.length());

^

Match the Error - 4

public class Sleigh

{

public static void main (String args[]) {

String s = new String;

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

s+=i;

System.out.println(s.length());

}

}

Sleigh.java:4: '(' or '[' expected

String s = new String;

^

1 error

Match the Error - 5

public class Sleigh

{

public static void main (String args[]) {

String s[] = new String[];

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

s[i]+=i;

System.out.println(s);

}

}

Sleigh.java:4: array dimension missing

String s[] = new String[];

^

1 error

Match the Error - 6

public class Sleigh

{

public static void main (String args[]) {

String s[] = new String({"Dasher","Donner","Blitzen"});

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

s[i]+=i;

System.out.println(s.length());

}

}

Sleigh.java:4: illegal start of expression

String s[] = new String({"Dasher","Donner","Blitzen"});

^

Sleigh.java:4: ')' expected

String s[] = new String({"Dasher","Donner","Blitzen"});

^

2 errors

Match the Error - 7

public class Sleigh

{

public static void main (String args[]) {

String s[] = new String[10];

for (int i = 1; i <= s.length; i++)

s[i]=i+"";

System.out.println(s[0]);

}

}

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10

at Sleigh.main(Sleigh.java:6)