Does anybody know how I can print out the phrase? ...
# java-and-jvm
j
Does anybody know how I can print out the phrase?
Copy code
public class PrintWord {
// The program prints a word by characters in a phrase using a for loop
// Declare Scanner

// Start with Main Method	
	public static void main(String[] args) { 
    java.util.Scanner input = new java.util.Scanner(<http://System.in|System.in>);


	
// Prompt for user input
	System.out.print("Enter a phrase: ");  


	String s = input.nextLine(); 
	System.out.print(s);  	

		int numOfI = 0;
		int numOfC = 0;
		int numOfS = 0; 
		for (int j = 0; j < s.length(); j++) {
			 
// Calculate counts of each character
		if (s.charAt(j) == 'I' || s.charAt(j) == 'i') {
			numOfI += 1;
		}
		else if (s.charAt(j) == 'C' || s.charAt(j) == 'c') {
			numOfC += 1;
		}
		else if (s.charAt(j) == 'S' || s.charAt(j) == 's') {
			numOfS += 1;
		}
		}

// Print out character counts
	System.out.println("This phrase contains: ");
	System.out.println(numOfI + "'I's");
	System.out.println(numOfC + "'C's");
	System.out.println(numOfS + "'S's"); 
		  	
	    		
      }		
    	
}
s
"phrase"? You mean the variable
s
?
Aren't you already printing it? What exactly is the problem?
Copy code
> javac PrintWord.java
> ls
PrintWord.class  PrintWord.java  build.clj  deps.edn  src  target
> java PrintWord
Enter a phrase: Hawaii
HawaiiThis phrase contains:
2'I's
0'C's
0'S's
Do you want a newline in there?
j
Copy code
System.out.print(s);
does not print what the user enters, I am stuck on this one. Thanks so much for your help!
s
Copy code
Enter a phrase: Hawaii
HawaiiThis phrase contains:
☝🏻 Yes, it does.
j
I just tested and now it's working as expected 🙂 thanks so much @seancorfield
👍🏻 1