Which escape sequence moves the cursor to the next line?
Q2
How do you place a double quote inside a string literal?
Q3
What is the output of System.out.println("A\tB\nC");?
Q4
Which declaration stores a single character?
Q5
What is the value of '5' - '0'?
Q6
Which comparison is true?
Q7
A variable of a reference type stores:
Q8
After String t = s;, how many String objects exist?
Q9
What happens when a method is called on a null reference?
Q10
Which statement about String objects is not true?
Q11
What is the output?
String s = "hello";
s.toUpperCase();
System.out.println(s);
Q12
Given String s = "Programming";, what does s.length() return?
Q13
Given String s = "Programming";, what does s.charAt(3) return?
Q14
Given String s = "Programming";, what does s.substring(0, 3) return?
Q15
Given String s = "Programming";, what does s.substring(3) return?
Q16
Given String s = "banana";, what does s.indexOf("na") return?
Q17
What does "banana".indexOf("xy") return?
Q18
What is the result of "Java".charAt(4)?
Q19
What is the output?
String a = "Java";
String b = "Java";
String c = new String("Java");
System.out.print((a == b) + " " + (a == c) + " " + a.equals(c));
Q20
Which is the safest way to test whether name holds exactly the text "Ali"?
Q21
What does "apple".compareTo("banana") return?
Q22
What does "Hello".equalsIgnoreCase("HELLO") return?
Q23
What is the output of System.out.println(" Java ".trim().length());?
Q24
What is the output?
String s = "mississippi";
System.out.print(s.replace('s', 'z'));
Q25
What is the output?
String s = "Wenzhou";
System.out.print(s.substring(2, 5) + s.length());
Q26
Which import is required to use Scanner?
Q27
Which statement correctly creates a Scanner that reads from the keyboard?
Q28
Which Scanner method reads an entire line including spaces?
Q29
A program calls nextInt() and then nextLine(). What does nextLine() usually
return?
Q30
Which method would you use to check that the user really typed an integer before reading
it?
Q31
What exception is thrown by nextInt() when the user types abc?
Q32
What is the output when the user types Ali Hassan at the prompt?
Scanner in = new Scanner(System.in);
String word = in.next();
System.out.print(word);
Q33
What is the output?
String s = "Java";
s += " SE";
s = s + 8;
System.out.print(s + " " + s.length());
Q34
Which expression converts the char variable digit (for example '7') into the
int value 7?
Q35Short answer
Draw the memory picture produced by the three lines below and
explain what each variable contains.
int n = 7;
String s = "Java";
String t = s;
Q36Short answer
Explain what “immutable” means for String and describe what
actually happens in memory when a program executes s = s + "!"; inside a loop that runs a
thousand times.
Q37Short answer
Write the three lines needed to read a student's full name and then
their age from the keyboard, in that order, without falling into the nextLine trap.
Q38Programming
Write a program Initials that reads a full name such as
Hamza Djigal on one line and prints the initials in upper case separated by dots
(H.D.). Use indexOf, substring and charAt; assume exactly two names.