《去哪网编程题》filename extension
生活随笔
收集整理的这篇文章主要介绍了
《去哪网编程题》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;/*** 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){//不包含.就返回-1System.out.println("null");}else {System.out.println(s.substring(index+1));}}}} 创作挑战赛新人创作奖励来咯,坚持创作打卡瓜分现金大奖总结
以上是生活随笔为你收集整理的《去哪网编程题》filename extension的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 《好未来编程题》 输入n个整数,输出出现
- 下一篇: 《网易编程题》分苹果