You are to write a Java application that Creates an ID from
Solution
Hi, Please find my implementation.
Please let me know in case of any issue.
import java.util.Scanner;
public class StringMethodTest {
public static void main(String[] args) {
// creating Scanner Object
Scanner sc = new Scanner(System.in);
//1 reading two words
System.out.print(\"Enter first word: \");
String first = sc.next();
System.out.print(\"Enter second word: \");
String second = sc.next();
String ID = \"\";
// getting last half of first
ID = ID + first.substring(first.length()/2);
// adding length of second in ID
ID = ID + second.length();
// adding first charactr of second in uppercase
ID = ID + Character.toUpperCase(second.charAt(0));
// printing ID
System.out.println(ID);
System.out.println();
//2
// getting path
System.out.println(\"Enter path of file: \");
String path = sc.next();
// finding index of first \'.\' from last
int index = path.lastIndexOf(\'.\');
if(index == -1){
System.out.println(\"no extensioj of file\");
}else{
System.out.println(\"The file extension is: \"+path.substring(index+1));
}
}
}
/*
Sample run:
Enter first word: georage
Enter second word: wealth
rage6W
Enter path of file:
xyx/trwe/pravesh/main.c
The file extension is: c
*/

