题目描述
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;
/**
* Created by Administrator on 2017/8/10.
*/
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()){
String s=sc.next();
int index=s.lastIndexOf(".");
if(index==-1){//不包含.就返回-1
System.out.println("null");
}else {
System.out.println(s.substring(index+1));
}
}
}
}