week 10 quiz l.
Download
Skip this Video
Download Presentation
Week 10 – Quiz!!

Loading in 2 Seconds...

play fullscreen
1 / 22

Week 10 – Quiz!! - PowerPoint PPT Presentation


  • 149 Views
  • Uploaded on

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; ->Loop never finishes. Spot the bug - 2.

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

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


Download Now An Image/Link below is provided (as is) to download presentation

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
1 st round
1st 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
Spot the bug -1

boolean santa=true;

while(santa=true)

santa=false;

->Loop never finishes

spot the bug 2
Spot the bug - 2

String reindeer;

BufferedReader in = new BufferedReader(System.in);

do {

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

reindeer=in.readLine();

} while(reindeer=="y");

-> Won’t repeat while loop

spot the bug 3
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
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

2 nd round
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
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
Match the Error - 2

public class Sleigh

{

public static void main (String args[]) {

String s;

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

}

}

match the error 3
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
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
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
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
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]);

}

}

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

public class Sleigh

{

public static void main (String args[]) {

String s = null;

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

}

}

Exception in thread "main" java.lang.NullPointerException

at Sleigh.main(Sleigh.java:5)

match the error 217
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 318
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 419
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 520
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 621
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 722
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)

ad