fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. String s=new String("hello world");//创建一个字符串
  14. int i,count=0;
  15. Scanner read=new Scanner(System.in);
  16. String c=read.nextLine().substring(0, 1);//输入一个字符
  17. for(i=0;i<s.length();i++){
  18. String d=s.substring(i,i+1);
  19. if(d.equals(c)) //判断输入字符与每个字符是否相等
  20. count++;
  21. }
  22. System.out.println(count);
  23. }
  24. }
Success #stdin #stdout 0.06s 711680KB
stdin
l
stdout
3