All please answer all questions and the programs are in Java. 1. Create a little
ID: 3696266 • Letter: A
Question
All please answer all questions and the programs are in Java.
1. Create a little program using command-line argument. Input (command line): java HelloBuddy John Mary Tom
Output: Hello John!
Hello Mary!
Hello Tom!
3. What is the value of the String S after the following line?
String S = (new String("arach")).substring(0,2) +
(new String("nophobia")).substring(3);
3. What is the output of the following code segment (trick: break)?
char x = ’A’;
while(x != ’D’){
switch(x){
case ’A’: System.out.println(x); x = ’D’;
case ’B’: System.out.println(x); x = ’C’; break;
case ’C’: System.out.println(x); x = ’D’;
default: continue;
}
}
Explanation / Answer
1.
class Echo {
public static void main (String args[]) {
for (int i = 0; i < args.length; i++)
System.out.println("Hello "+args[i]+"!");
}
}
2. S = "arhobia"
3. output :
A
D
C