1 / 22

Week 10 – Quiz!!

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.

saki
Download Presentation

Week 10 – Quiz!!

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Week 10 – Quiz!!

  2. 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

  3. Spot the bug -1 boolean santa=true; while(santa=true) santa=false; ->Loop never finishes

  4. 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

  5. Spot the bug - 3 int i = 0; while (i < 10) System.out.println(i); i++; System.out.println(“Finished”); -> Infinite loop

  6. 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

  7. 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

  8. Match the Error - 1 public class Sleigh { public static void main (String args[]) { String s = null; System.out.println(s.length()); } }

  9. Match the Error - 2 public class Sleigh { public static void main (String args[]) { String s; System.out.println(s.length()); } }

  10. 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()); } }

  11. 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()); } }

  12. 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); } }

  13. 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()); } }

  14. 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]); } }

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

  16. 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)

  17. 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

  18. 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()); ^

  19. 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

  20. 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

  21. 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

  22. 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)

More Related