Advertisement
fosterbl

CountS.java

Jan 22nd, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.40 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class CountS{
  4.     public static void main(String[] args){
  5.         Scanner kb = new Scanner(System.in);
  6.         System.out.print("Enter a word: ");
  7.         String word = kb.next();
  8.  
  9.         int sCount = 0;
  10.         for(int i = 0; i < word.length(); i++){
  11.             String letter = word.substring(i,i+1);
  12.             if( letter.equals("s") ) sCount++;
  13.         }
  14.         System.out.print("There are " + sCount + " s's");
  15.     }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement