Write code to get File Extension
Fill in the missing code.
public class Main { public static void main(String[] argv) { String name = "book2s.com"; System.out.println(getFileExtension(name)); } public static String getFileExtension(String name) { String ext = ""; if (name.contains(".")) { ext = //your code here } return ext; } }
//package com.book2s; public class Main { public static void main(String[] argv) { String name = "book2s.com"; System.out.println(getFileExtension(name)); }/* w ww. jav a2 s. c o m*/ public static String getFileExtension(String name) { String ext = ""; if (name.contains(".")) { ext = name.substring(name.lastIndexOf(".") + 1); } return ext; } }