去哪儿笔试:filename extension
2017-08-18 23:24
309 查看
去哪儿笔试:filename extension
题目描述Please create a function to extract the filename extension from the given path,return the extracted filename extension or null if none.
输入描述:
输入数据为一个文件路径
输出描述:
对于每个测试实例,要求输出对应的filename extension
示例1
输入
Abc/file.txt
输出
txt
思路:
考查字符串的常用方法
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()) { String line = sc.nextLine(); int index = line.lastIndexOf('.') + 1; String result = (index == 0) ? "null" : line.substring(index); System.out.println(result); } sc.close(); } }
相关文章推荐
- 去哪儿2017校园招聘笔试题——获得文件扩展名filename extension
- CreateProcess error=206, The filename or extension is too long"的一个解决方案
- 去哪儿笔试:身份证分组
- 去哪儿2015笔试题JAVA实现
- 去哪儿笔试题——排序数组循环移位后查找
- fullpath & filename & extension
- 去哪儿笔试解决方案二(java)
- 去哪儿笔试解决方案二(java)
- 去哪儿笔试:座位安排问题
- iOS常见问题之 "_kUTTagClassFilenameExtension", referenced from:
- 去哪儿2015笔试题:寻找字符串的差异
- 去哪儿笔试:部分和问题 java
- HowTo: Bash Extract Filename And Extension In Unix / Linux
- 去哪儿笔试题 首个重复字符
- 名企笔试:去哪儿2015研发笔试题(寻找Coder)2017-03-24 算法爱好者
- Mailscanner Attempt to hide real filename extension (themeManager.x10.rel)
- 去哪儿2017校园招聘笔试题——统计字符串中最先出现三次的字符
- 去哪儿---2015笔试编程题
- string - How to get the filename without the extension from a path in Python? - Stack Overflow
- Swift学习笔试19——扩展(Extension)