Question: Exercise 1 Description For this lab you will write a Java program that prompts the user to enter a string. Your program should use a
Exercise 1 Description
For this lab you will write a Java program that prompts the user to enter a string. Your program should use a loop to count the characters of the string that are digits - any character between '0' and '9' - and then output a total count. In the ClosedLab05 folder, create a new Java program named Lab05a.java for this problem.
Exercise 1 Sample Output
This is a sample transcript of what your program should do. Items in bold are user input and should not be put on the screen by your program. Enter a string to count the digits in: R2-D2 Your string contains 2 digits. A second run of the code might give this output: Enter a string to count the digits in: thx-1138 Your string contains 4 digits. Make sure your code gives the appropriate output if there are no digits in the string: Enter a string to count the digits in: The quick brown fox jumped over the lazy dog. Your string contains 0 digits. NOTE: For this assignment you should use the Character.isDigit() method. This method returns a true value if the character being tested is a digit between 0 and 9 and a false value otherwise. For example, the following code snippet displays the message "That's a digit!": char testValue = '9'; if (Character.isDigit(testValue)) { System.out.println("That's a digit!"); }
Exercise 2 Description
For this lab you will write a Java program that prompts the user to enter a positive integer. Your program should use a loop to compute a Hailstone Series, using that integer as a start point. The Hailstone series is defined as follows: start with any integer n strictly greater than 0. If n is even, then the next value in the series is n/2. If n is odd, then the next value in the series is 3*n + 1. In the ClosedLab05 folder, create a new Java program named Lab05b.java for this problem.
Exercise 2 Sample Output
This is a sample transcript of what your program should do. Items in bold are user input and should not be put on the screen by your program. Enter a starting value: 19 19, 58, 29, 88, 44, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1 A second run of the code might look like this: Enter a starting value: 18 18, 9, 28, 14, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1 Note that when the series reaches the value of 1, the sequence will start repeating: 1, 4, 2, 1 ... At this point we say that the series has converged and our loop should stop rather than repeat infinitely. Make sure your loop stops when it reaches the value of 1.
Exercise 3 Description
For this lab you will write a Java program to reverse a string. Your program will take a string from the user and use a loop to output the reverse of that string to the console. Create a new Java program named Lab05c.java for this problem.
Exercise 3 Sample Output
This is a sample transcript of what your program should do. Items in bold are user input and should not be put on the screen by your program. Enter a string to reverse: Hello World! !dlroW olleH A second run of this code might produce the following output: Enter a string to reverse: The quick brown fox jumped over the lazy dog. .god yzal eht revo depmuj xof nworb kciuq ehT HINT: Write your loop to perform a System.out.print() of a single character on each iteration of that loop. Think about what order the characters need to appear in, and what does that mean for the logic of that loopStep by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
