Open Jayyijianyi opened 4 years ago
// ** // StringExercise.java // // Play with String objects // ** public class StringExercise { public static void main (String[] args) { String college = new String ("College of Arts and Sciences"); ____; // part (a) int stringLength; String change1, change2, change3; ____; // part (b) System.out.println (college + " contains " + stringLength + " characters."); change1 = __; // part (c) System.out.println ("The string is all in upper case: " + change1); change2 = __; // part (d) System.out.println ("All capital O's are replaced with the asterisk character: " + change2); change3 = __; // part (e) System.out.println ("The final string is " + change3); } }
Write a program called “FunnyString” that asks the user to enter a favourite color, food, animal and the first name of a friend. Use a Scanner object and read one thing per line. The program should than print the following: For example if the user entered blue for color, burger for food, cat for the animal and Jack for the friend the output will be:
I had a dream that Jack ate a blue cat and said it tasted like burger !
Write a program that read a string for a date in the format day/month/year and displays it as in the format day.month.year. For example if the input is 13/09/18 the output should be 13.09.18 .
Hint: Search in the class String for the appropriate method to solve this problem.
Write a program that reads a four-digit number (such 2018) as a String and then display it one digit per line like so: 2 0 1 8
(Use charAt() method from String, Think about the right type for the variables you use).
Next, print the sum of the digits.
Hint: Use Integer.parseInt() to convert digits to integers.
Submission SGA.java