in Java Use String class methods to identify parts of text Y

in Java, Use String class methods to identify parts of text

You are to write a Java application that

Creates an ID from two words.

The ID has the form: LastHalfOfWord1 + LengthOfWord2 + UppercaseFirstLetterOfWord2

For example, if the two words are george and washington, the ID will be rge10W

Extracts a file extension from a file path.

For example, if the file path is /some/path/to/file/myfile.java, the program would print: The file extension is \".java\".

Solution

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

*/

in Java, Use String class methods to identify parts of text You are to write a Java application that Creates an ID from two words. The ID has the form: LastHalf
in Java, Use String class methods to identify parts of text You are to write a Java application that Creates an ID from two words. The ID has the form: LastHalf

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site