-
-
Save codedeman/4c0ddba7a921d9f434593d268dceacd1 to your computer and use it in GitHub Desktop.
count word
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class ChainTest { | |
int count = 0; | |
public static final char SPACE = ' '; | |
public static final char TAB = '\t'; | |
public static final char BREAK_LINE = '\n'; | |
public void countWord(String chain) | |
{ | |
for(int i = 0;i<chain.length();i++) | |
{ | |
if (chain.startsWith("a")&& chain.charAt(i) != SPACE && chain.charAt(i) != TAB) | |
{ | |
count += 1; | |
} | |
} | |
System.out.print("character is:"+chain+"the number of occurrences is:"+count); | |
} | |
public void Input() | |
{ | |
String s1; | |
ChainTest chain = new ChainTest(); | |
Scanner scanner = new Scanner(System.in); | |
System.out.print("enter a string:"); | |
s1 = scanner.nextLine(); | |
chain.countWord(s1); | |
} | |
public static void main(String[] args) | |
{ | |
ChainTest chain = new ChainTest(); | |
chain.Input(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment