找出字符串中第一个只出现一次的字符
2015-08-21 19:05
274 查看
import java.util.Scanner; public class GetOneChar { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String str = scan.nextLine(); int count = 0; for (int i = 0; i < str.length(); i++) { int a = str.indexOf(str.charAt(i)); int b = str.lastIndexOf(str.charAt(i)); if(a-b==0){ System.out.println(str.charAt(i)); return; } count++; } if(count==str.length()) System.out.println("."); } }
样例输入 | asdfasdfo |
---|---|
样例输出 | o |
1、只输出第一次出现的
2、没有的话输出“.”
相关文章推荐
- bootstrap模态框Esc键不关闭
- 03-树3. Tree Traversals Again (25)将先序遍历和中序遍历转为后序遍历
- java 遍历MAP
- hihocoder 1110 正则表达式
- STM32的PWM输入模式设置并用DMA接收数据
- WebService只能在本地使用,无法通过网络访问的解决办法
- Oracle 学习之卸载Oracle 11g
- main函数的参数(一)
- iOS 屏幕适配
- 04---XML编程整理
- Linux命令(7)
- PAT 1007 A除以B (大数相除)
- js的表达式,运算符,与优先级
- linux定时任务的设置
- FaxConInit
- hdu 5412 CRB and Queries(树套树模板,区间第K大)
- 大型网站架构技术一览
- Codeforces Gym 100338C C - Important Roads tarjan
- C# .net 抓取网页内容
- instanceof关键字详解