《去哪网编程题》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个整数,输出出现
- 下一篇: 《网易编程题》分苹果