Mid#1 (Q1+4)%E2%80%AB%E2%80%AC.pdf - CSC111_Mid#1(1433 – 1434 – first semester Q1 What is the output for the following code segments[4 Marks.75

Mid#1 (Q1+4)%E2%80%AB%E2%80%AC.pdf - CSC111_Mid#1(1433 –...

This preview shows page 1 - 2 out of 2 pages.

CSC111_Mid#1 (1433 1434) first semester Q1: What is the output for the following code segments: [4 Marks (.75+1.5+.75+1)] a) char ch = 'c'; for(int i=0;i<2;i++){ switch(ch){ case 'a': System.out.print(ch++); break; case 'b':System.out.print(ch++); break; case 'c':System.out.print(--ch) ; case 'd':System.out.print(ch--) ; break; default:System.out.println("invalid");}} b) final int END=-1; int number=0,counter=0, count=0; while(number!=END){ counter++; number=console.nextInt(); if(number%5==0){ count=(number%2+5); System.out.println(counter+" "+cont); continue;} else if(number<-5) break; count=(number*5+2); System.out.println(counter+" "+cont);} System.out.println(counter+" "+count); c) int t=0, j=1; k=2; if (++t==j || ++k>0) System.out.print(t+ " "+j+" "+k); Output: 1 1 2 d) String s="My First Exam"; System.out.println(s.substring(3,s.length()).charAt(3)); System.out.printf("%8.2f%n",s.indexOf("Hi")+ 5.4); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 S 4 . 4 0 Output: bba B) Input Output 10 1 5 3 2 17 -6 3 17
Image of page 1

Subscribe to view the full document.

Q4: Programming Problem [4 Marks] Write a Java program that reads string
Image of page 2
  • Fall '10
  • ZuhairShentuf

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes