zoukankan      html  css  js  c++  java
  • 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
     1 import java.util.Scanner;
     2 /**
     3  * 
     4  * Please create a function to extract the filename extension from the given path, return the extracted filename extension or null if none.
     5  *     1、用"/" 分割取最后一项
     6  *  2、用"." 分割取最后一项
     7  */
     8 public class Main {
     9     public static void main(String[] args) {
    10         Scanner sc = new Scanner(System.in);
    11         String s = sc.nextLine();
    12         String[] ss = s.split("/");
    13          s = ss[ss.length-1];
    14         String[]s1=s.split("\."); // .是转义字符 不能直接编写
    15         if (s1.length>1) {
    16             s = s1[s1.length-1];
    17         }else {
    18             s=null;
    19         }    
    20         System.out.println(s);
    21     }
    22 }
  • 相关阅读:
    第三天-基本数据类型 int bool str
    第二天-while循环 格式化输出 运算符 编码
    第一天-python基础
    Mysql
    Mysql
    Mysql
    Mysql
    Mysql
    Mysql
    Php
  • 原文地址:https://www.cnblogs.com/the-wang/p/8981527.html
Copyright © 2011-2022 走看看