Question: I'm in java one and need help with this code. please follow the directions given and test your program to make sure it works as
I'm in java one and need help with this code. please follow the directions given and test your program to make sure it works as it is required. I will apreciate your help. thank you.please use the given code( FILL THE REQUIRED INFORMATION TO MAKE IT WORK ( in this case the for loop).
use this code
cp ~lkoperski/1404_Lab/Exercises/Exercise12.java .

Programming Concepts
1. String library
Exercise Location
For this exercise, you will copy a program from my directory into yours. It doesn't matter what directory this exercise is located in. You will need to copy this command and paste it into Loki:
cp ~lkoperski/1404_Lab/Exercises/Exercise12.java .
Exercise Description
You will be using String methods to analyze how many words, lines, and characters there are in a String.
int length() ?Returns the length of a String
char charAt(index) ?Returns the character at a specific index of the String
You must loop through each character in the String.
>> Each word ends with either a space, or a period. If you read in one of those characters, then update the word count.
>> Each line ends with a newline character. If you read in one of those ' ', then update the line count.
>> For each character that isn't a newline character, update the character count.
output example
user@loki:~$ java Exercise12
----------------------------------------------------------------------------
Once upon a time, there was a very bad man. He smelled funky, sang awful pop songs, and told annoying knock-knock jokes.
Nobody liked him. Then, one day, he slipped on some ice and died. Everyone was happy after that.
The end.
----------------------------------------------------------------------------
Number of characters: 222 Number of words: 48 Number of lines: 7
1 public class Exercise12 2 t 3 public static void main (String [] args) String text"Once upon a time, there was a very bad man. In"+ "He smelted funky, sang awful pop songs, and told annoying knock-knock jokes In+ n+ Nobody liked him. Then, one day, he slipped on some ice and died Everyone was happy after that.In"+ In+ 10 n+ The end. 12 13 14 15 16 17 18 19 20 21 n) System.out.print(I System.out.print( 'In" + text); int cha rCount = ; int wordCount: int lineCount = 0; for (/Loop through the length of the String /) // If the character at the current position in the string is a space, period, or comma, then you have encountered a word // If the character at the current position in the string is a newline, then you have encountered a line // Otherwise, if the character at the current position in the string is anything but a newline, 23 24 25 26 27 28 29 30 31 32 //then you have encountered a regular character System.out.println("In System.out.printf "Number of characters: %dInNumber of words: % number of lines : %d\ dIn ,charCount, wordCount, lineCount); 34 35
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
