Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use the Ruby String class to do the following. Write one Ruby program to do all.

ID: 3774419 • Letter: U

Question

Use the Ruby String class to do the following. Write one Ruby program to do all. 1. Read an input string - Print result (The input string) 2. Find the length of the input string. - Print result 3. Display string from backward. - Print result 4. Count number of words in string. - Print result 5. Input another string. - Print result (The second input string) 6. Concatenate the second string to the first string – Print result 7. Compare the two strings they are exact equal or not. - Print result 8. Check if the first string is palindrome or not. - Print result 9. Extract the substring of 5 characters anywhere within the first string - Print result 10. Reverse the first string. Print result 11. Convert the first string to all lowercase. - Print result 12. Convert the first string to all uppercase. - Print result.

Explanation / Answer

Note : I will complete this

RubyString.java

import java.util.Scanner;

public class RubyString {

   public static void main(String[] args) {
  
       String str,revstr,str2,str3;
       int strLen;
      
       Scanner kb=new Scanner(System.in);
       System.out.print("Enter a String :");
       str=kb.nextLine();
       System.out.println("You Entered String :"+str);
       strLen=str.length();
       System.out.println("The Length of the String is :"+strLen);
       revstr=revString(str);
       System.out.println("The Reverse of the String is :"+revstr);
       String arr[]=str.split(" ");
       System.out.println("The Number of Words in the String :"+arr.length);
       System.out.print("Enter another String :");
       str2=kb.nextLine();
       System.out.println("You Entered String :"+str2);
       str3=str+str2;
       System.out.println("After Concatinating the First String to Second String is :"+str3);
       System.out.println("Comparing the first String to the Second String :");
       if(str.equals(str2))
           System.out.println("First String and Second String are Equal");
       else
           System.out.println("First String and Second String are Not Equal");
      
      

   }

   private static String revString(String str) {
       String strrev="";
       for(int i=str.length()-1;i>=0;i--)
       {
           strrev+=str.charAt(i);
       }
       return strrev;
   }

}