OOPS.................

Friday, January 2, 2009

What will happen when you attempt to compile and run the following code?

import java.util.*;
public class Scan{
public static void main(String argv[]){
new Scan();
}
Scan(){
String input = "Richard,Libby,Hattie,Alice";
Scanner scan = new Scanner(input).useDelimiter(",");
while(scan.hasNext()){
System.out.print(scan.next());
}
}
}

Answers:
1:Compile time error, Scanner has no useDelimiter method.
2:Compilation and output of "Richard,Libby,Hattie,Alice"
3:Compilation but no output at runtime.
4:Compilation and output of "RichardLibbyHattieAlice"

No comments: