Java: How to count a character in a String using Loop? -


I'm thinking how many times the number of characters written by the user appears in the string that is a user. I have to use loops and if / else statements I think I'm on the right track, but when I'm compiling (using the blues), error message "Icons-variable status can not be found" Any help greatly appreciated Thanks, thanks.

  string input; String sentence; String letter; Int Time = 0; Int position; Scanner KB = new scanner (System.in); System.out.print ("Please enter a string:"); Input = kb.nextLine (); Sentence = input.toLowerCase (); System.out.print ("Thank you. \ NPlease enter the character you want to count:"); Letter = kb.next (); (Status = 0; condition & lt; = sentence.length (); condition ++) {if (sentence.chartAut (condition) == letter) {times ++; }} System.out.print ("+ + +" + + "sentence + sentence" + + + + letter "has" + bar + "order;)    

First of all, your statement contains a typo:

  sentence. Posotion   

should be

  sentence.start (status)   

Then, you assign to equality test rather than :

  if (sentence. Chat (status) = letter) should be {  

  if (sentence .chart (status) == letter) {  

After this, you will see a string If there are several ways to resolve this, there is one side (supposedly letter is at least one letter):

  If (sentence. Chat (position) == In the letter and end, you probably can not check the past at the end of the string:  
 for  (position = 0; The status should be   

 for  (position = 0; Status & lt; Sentence.length (); Status ++) {   

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -