TOPIC 8 EXERCISES

14.Java programming exercises with solutions on java Strings. 8 different ways to convert int to String ; java programming problems and solutions on String: 

Part of the document

TOPIC 8 EXERCISES

Tracing Exercises

1. Suppose you have the following declaration.

String str;
Which of the following values can be assigned to the variable str? If any value cannot be assigned,
explain why not.

(a) "dog" (b) "4315" (c) 43 (d) 4.5 (e) 'h'
2. What value will this string get after each of the following?
String day;
Scanner kybd = new Scanner(System.in);
(a) day = kybd.next();
and user enters "Tuesday"
(b) day = kybd.next(); and user enters "next Tuesday"
(c) day = kybd.nextLine(); and user enters "Tuesday the 24th"
(d) day = kybd.nextLine(); and user enters "last Wednesday"



3. Show how to represent each of the following (assume that all variables have been declared to
have type String):

(a) the character in position 5 of arr (b) the character in the first position of hold
(c) the character in position 3 of str (d) the character in position 1 of line
(e) the last character in hope (Hint: this one is harder than the others-why?)