您的位置:首页 > 其它

去哪儿笔试: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();
}
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: