《去哪网编程题》filename extension
生活随笔
收集整理的這篇文章主要介紹了
《去哪网编程题》filename extension
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
題目描述
Please create a function to extract the filename extension from the given path,return the extracted filename extension or null if none.
輸入描述:
輸入數(shù)據(jù)為一個(gè)文件路徑
輸出描述:
對(duì)于每個(gè)測(cè)試實(shí)例,要求輸出對(duì)應(yīng)的filename extension
示例1
輸入
Abc/file.txt
輸出
txt
解析:注意可能沒(méi)有擴(kuò)展名的情況就好了
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));}}}} 創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的《去哪网编程题》filename extension的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 《好未来编程题》 输入n个整数,输出出现
- 下一篇: 《网易编程题》分苹果