Al-ZaytoonahUniversity of Jordan جـامعـة الـزيتـونــــة األردنيــة
Course Name: Programming Concepts
Instructor: Nesreen Hamad
Lab #4
Name of student Number of student
Q1. What is the output of the following code segments
char op='?';
switch(op)
{case '*' : ! = exclamation mark
System.out.println(op + " = multiply" ); End of output question
break; *
case '?':
op='!';
System.out.println(op + " = exclamation
mark");
default:
op='*';
System.out.println("End of output question");
}
System.out.println(op);
int x=10;
char ch='*'; * 103
if(x<=10) 12
if(ch=='+')
System.out.println(ch + " " + x);
else if(ch=='?')
System.out.println((x+3));
else
System.out.println(ch + " " + x + 3);
else
System.out.println((x+4));
x=x+2;
System.out.println(x);
int count;
for (count=1;count<=5;count++) Infinite loop
{count = 1;
System.out.println( count );
}
int count; 10
for (count=10;count>=-2;count-=4) 6
System.out.println(count); 2
System.out.println(count); -2
-6
int count; 13
QF01/2611– page 1/2
Al-ZaytoonahUniversity of Jordan جـامعـة الـزيتـونــــة األردنيــة
for (count=1;count<=10;count+=4)
if(count==3)
count+=4;
else
count+=2;
System.out.println(count);
double i,sum=0;
for(i=1;i<=3;i++) 14.0
sum=sum+pow(2,i);
System.out.println(sum);
:Q2. Convert the following to switch
Scanner input=new Scanner(System.in);
char operator;
System.out.println("Enter the operator");
operator=input.next().charAt(0);
if(operator== '>')
System.out.println("greater than operator");
else if(operator=='<')
System.out.println("less than operator");
else
System.out.println("not an allowed operator");
Scanner input=new Scanner(System.in);
char operator;
System.out.println("Enter the operator");
operator=input.next().charAt(0);
switch(operator)
{ case '>':
System.out.println("greater than operator");
break;
case '<':
System.out.println("less than operator");
break;
default:
System.out.println("not an allowed operator");
}
QF01/2611– page 2/2