Sample Input:
Enter the path: C:\Users\User\Pictures\Ferrai.jpeg
Sample Output:
Path: C:\Users\User\Pictures\
Name: Ferrai
Extention: jpeg
import java.util.Scanner;
public class Path
{
public static void main()
{
Scanner s=new Scanner(System.in);
System.out.print("Enter the path: ");
String str=s.nextLine();
String a[]=str.split("\\\\");
String b[]=a[a.length-1].split("\\.");
String f="";
for(int x=0; x<a.length-1; x++)
f=f+a[x]+"\\";
System.out.println("Path: " + f);
System.out.println("Name: " + b[0]);
System.out.println("Extention: " + b[1]);
}
}
Enter the path: C:\Users\User\Pictures\Ferrai.jpeg
Sample Output:
Path: C:\Users\User\Pictures\
Name: Ferrai
Extention: jpeg
import java.util.Scanner;
public class Path
{
public static void main()
{
Scanner s=new Scanner(System.in);
System.out.print("Enter the path: ");
String str=s.nextLine();
String a[]=str.split("\\\\");
String b[]=a[a.length-1].split("\\.");
String f="";
for(int x=0; x<a.length-1; x++)
f=f+a[x]+"\\";
System.out.println("Path: " + f);
System.out.println("Name: " + b[0]);
System.out.println("Extention: " + b[1]);
}
}
No comments:
Post a Comment
Please write your comment in the box below...