LearnJavaInterview Questions(String Problems)

                                                                                   


STRING PROBLEMS
AppendTwoGivenStringsAndContactIfDoubleCharExistsOmitOneCharacter

import java.util.Scanner;

public class AppendTwoGivenStringsAndContactIfDoubleCharExistsOmitOneCharacter {
public String concat(String a,String b) {
    if(a.length()!=0&&b.length()!=0&&a.charAt(a.length()-1)==b.charAt(0))
        return a+b.substring(1);
    return a+b;
}
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        AppendTwoGivenStringsAndContactIfDoubleCharExistsOmitOneCharacter  obj=
new AppendTwoGivenStringsAndContactIfDoubleCharExistsOmitOneCharacter ();
        Scanner sc=new Scanner(System.in);
        String a=sc.next();
        String b=sc.next();
           System.out.println("The given strings are: "+a+"  and  "+b);
              System.out.println("The string after concatination are: "+
obj.concat(a,b));
    }

}

ChangeLowerCaseToUpperCase

import java.util.Scanner;

public class ChangeLowerCaseToUpperCase {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc=new Scanner(System.in);
        String a=sc.next();
        String b=a.toUpperCase();
        System.out.println("the original string is:"+a);
        System.out.println("the uppercase string is:"+b);
    }

}

ChangeUpperCaseCharToLowerCase

import java.util.Scanner;

public class ChangeUpperCaseCharToLowerCase {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc=new Scanner(System.in);
        String a=sc.next();
        String b=a.toLowerCase();
        System.out.println("the original string is:"+a);
        System.out.println("the lowercase string is:"+b);
    }

}

ChcekWheatherTwoStringObjectsContainsTheSameData

import java.util.Scanner;

public class ChcekWheatherTwoStringObjectsContainsTheSameData {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String a=sc.next();
String b=sc.next();
String c=sc.next();
boolean d=a.equals(b);
boolean e=a.equals(c);
System.out.println("\"" + a + "\" equals \"" +
        b + "\"? " + d);
    System.out.println("\"" + a + "\" equals \"" +
        c + "\"? " + e);
    }

}

CheckTheStringItsStartsWithSpecifiedString

import java.util.Scanner;

public class CheckTheStringItsStartsWithSpecifiedString {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String a=sc.next();
String b=sc.next();
String c=sc.next();
boolean d=a.startsWith(c);
boolean e=b.startsWith(c);
System.out.println("a starts with:"+d);
System.out.println("b starts with:"+e);
    }

}

CheckWheatherAGivenStringEndsWithTheContentsOfAnotherString

import java.util.Scanner;

public class CheckWheatherAGivenStringEndsWithTheContentsOfAnotherString {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String a=sc.next();
String b=sc.next();
String c=sc.next();
boolean d=a.endsWith(c);
boolean e=b.endsWith(c);
System.out.println("\"" + a + "\" ends with " +
        "\"" + c + "\"? " + d);
    System.out.println("\"" + b + "\" ends with " +
        "\"" + c + "\"? " + e);
    }

}

ComapreTwoStringsLexicographicallyIgnoreCaseDiffrences

import java.util.Scanner;

public class ComapreTwoStringsLexicographicallyIgnoreCaseDiffrences {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String a=sc.next();
String b=sc.next();
int c=a.compareToIgnoreCase(b);
if(c<0) {
    System.out.println(a+" less to the:"+b);
}
else if(c==0) {
    System.out.println(a+" equals to the:"+b);
}
else {
    System.out.println(a+" greater to the:"+b);
}
    }

}

CompareAGivenStringSpecifiedStringBuffer

import java.util.Scanner;

public class CompareAGivenStringSpecifiedStringBuffer {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String a=sc.next();
String b=sc.next();
StringBuffer c=new StringBuffer(a);
System.out.println("the string a is:"+a.contentEquals(c));
System.out.println("the string b is:"+b.contentEquals(c));

    }

}

CompareTwoStringsLexicographically

import java.util.Scanner;

public class CompareTwoStringsLexicographically {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String a=sc.next();
String b=sc.next();
int result=a.compareTo(b);
if(result<0) {
    System.out.println(a+" less than the:"+b);
}
else if(result==0) {
    System.out.println(a+" equals to the:"+b);
}
else {
    System.out.println(a+" greater to the:"+b);
}
    }

}

CompareTwoStringToSpecifiedCharcaterSequence

import java.util.Scanner;

public class CompareTwoStringToSpecifiedCharcaterSequence {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String a=sc.next();
String b=sc.next();
CharSequence c=sc.next();
System.out.println("compare a:"+a.contentEquals(c));
System.out.println("compare b:"+b.contentEquals(c));
    }

}

ConcatTwoStringOfAnotherNewString

import java.util.Scanner;

public class ConcatTwoStringOfAnotherNewString {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String a=sc.next();
String b=sc.next();
System.out.println("the string 1 is:"+a);
System.out.println("the string 2 is:"+b);
String c=a.concat(b);
System.out.println("the concate string is:"+c);
    }

}

CountAndPrintAllTheDuplicateElementInString

public class CountAndPrintAllTheDuplicateElementInString {
static final int maxchar=256;
static void Countchar(String a,int []b) {
    for(int i=0;i<a.length();i++) {
        b[a.charAt(i)]++;
    }
}
    static void showDuplicates(String c)
    {
        int d[]=new int[maxchar];
        Countchar(c,d);
        for(int i=0;i<maxchar;i++)
            if(d[i]>1)
                System.out.printf("%c apperars %d times\n",i,d[i]);
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
String a="W3resources";
System.out.println("The given string is:"+a);
System.out.println("TheDuplicate char and count is:");
showDuplicates(a);
    }
   

}

CreateANewStringObjectWithTheContentsOfACharacterArray

import java.util.Scanner;

public class CreateANewStringObjectWithTheContentsOfACharacterArray {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
char[] b=new char[]{'1','2','3','4'};
String c=String.copyValueOf(b,1,3);
System.out.println("The Book Contains:"+c+" pages...");
    }

}

CreateAUniqueIdentifierAGivenString

import java.util.Scanner;

public class CreateAUniqueIdentifierAGivenString {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String a=sc.next();
int hashcode=a.hashCode();
System.out.println("the hash for "+a+" is "+hashcode);
    }

}

DivideAStringInNEqualParts

public class DivideAStringInNEqualParts {

   
        // TODO Auto-generated method stub
        static void splitString(String str1, int n) {
              int str_size = str1.length();
              int part_size;
              if (str_size % n != 0) {
               System.out.println("The size of the given string is not divisible by "
+ n);
               return;
              } else {
               System.out.println("The given string is: " + str1);
               System.out.println("The string divided into " + n +
" parts and they are: ");
               part_size = str_size / n;
               for (int i = 0; i < str_size; i++) {
                if (i % part_size == 0) System.out.println();
                System.out.print(str1.charAt(i));
               }
              }
    }
        public static void main(String[] args) {
              String str1 = "abcdefghijklmnopqrstuvwxy";
              int split_number = 5;
              splitString(str1, split_number);
             }
       

}

FindMaximunOccuringCharacterInString

public class FindMaximunOccuringCharacterInString {
    static final int N = 256;
     static char MaxOccuringChar(String str1) {
      int ctr[] = new int[N];
      int l = str1.length();
      for (int i = 0; i < l; i++)
       ctr[str1.charAt(i)]++;
      int max = -1;
      char result = ' ';

      for (int i = 0; i < l; i++) {
       if (max < ctr[str1.charAt(i)]) {
        max = ctr[str1.charAt(i)];
        result = str1.charAt(i);
       }
      }

      return result;
     }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
         String str1 = "test string";
          System.out.println("The given string is: " + str1);
          System.out.println("Max occurring character in the given string is: " +
MaxOccuringChar(str1));
    }

}

FirstNonRepeatingCharacterInString

import java.util.Scanner;

public class FirstNonRepeatingCharacterInString {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc=new Scanner(System.in);
        String a=sc.next();
        System.out.println("the string is:"+a);
        for(int i=0;i<a.length();i++) {
            boolean unique=true;
            for(int j=0;j<a.length();j++) {
                if(i!=j && a.charAt(i)==a.charAt(j)) {
                    unique=false;
                    break;
                }
            }
            if(unique) {
                System.out.println("the first non repeating character in string is:"+
a.charAt(i));
            }
        }
    }

}

GeTheContentsOfAGivenStringAsAByteArray

import java.util.Scanner;

public class GeTheContentsOfAGivenStringAsAByteArray {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String a=sc.next();
byte b[]=a.getBytes();
String c=new String(b);
System.out.println("the new string is:"+c);
    }

}

GetTheCanonicalRepresentationOfAStringObject

import java.util.Scanner;

public class GetTheCanonicalRepresentationOfAStringObject {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

String a="Java Exercises";
String b=new StringBuffer("Java").append(" Exercises").toString();
String c=b.intern();

System.out.println("a==b? "+(a==b));
System.out.println("a==c? "+(a==c));
    }

}

GetTheCharAtTheGivenIndexInAString

import java.util.Scanner;

public class GetTheCharAtTheGivenIndexInAString {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String a=sc.next();
System.out.println("the original string is:"+a);
int index1=a.charAt(0);
int index2=a.charAt(10);
System.out.println("the index1 char is:"+(char)index1);
System.out.println("the index2 char is:"+(char)index2);
    }

}

GetTheIndexOfAllTheCharactersOfTheAlphabet

import java.util.Scanner;

public class GetTheIndexOfAllTheCharactersOfTheAlphabet {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
       
        String str="The quick brown fox jumps over the lazy dog.";
        //The quick brown fox jumps over the lazy dog.
       
        int a = str.indexOf("a", 0);
        int b = str.indexOf("b", 0);
        int c = str.indexOf("c", 0);
        int d = str.indexOf("d", 0);
        int e = str.indexOf("e", 0);
        int f = str.indexOf("f", 0);
        int g = str.indexOf("g", 0);
        int h = str.indexOf("h", 0);
        int i = str.indexOf("i", 0);
        int j = str.indexOf("j", 0);
        int k = str.indexOf("k", 0);
        int l = str.indexOf("l", 0);
        int m = str.indexOf("m", 0);
        int n = str.indexOf("n", 0);
        int o = str.indexOf("o", 0);
        int p = str.indexOf("p", 0);
        int q = str.indexOf("q", 0);
        int r = str.indexOf("r", 0);
        int s = str.indexOf("s", 0);
        int t = str.indexOf("t", 0);
        int u = str.indexOf("u", 0);
        int v = str.indexOf("v", 0);
        int w = str.indexOf("w", 0);
        int x = str.indexOf("x", 0);
        int y = str.indexOf("y", 0);
        int z = str.indexOf("z", 0);

        // Display the results of all the indexOf method calls.
        System.out.println(" a  b c  d e  f  g h i  j");
        System.out.println("=========================");
        System.out.println(a + " " + b + " " + c + " " + d + " " +
                           e + " " + f + " " + g + " " + h + " " +
                           i + " " + j + "\n");

        System.out.println("k  l  m  n  o  p q  r  s  t");
        System.out.println("===========================");
        System.out.println(k + " " + l + " " + m + " " + n + " " +
                           o + " " + p + " " + q + " " + r + " " +
                           s + " " + t + "\n");

        System.out.println("u  v  w  x  y  z");
        System.out.println("================");
        System.out.println(u + " " + v + " " + w + " " + x + " " +
                           y + " " + z);

    }

}

GetTheLastIndexOfAStringWithInAString

public class GetTheLastIndexOfAStringWithInAString {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
         String str = "The quick brown fox jumps over the lazy dog.";

            // Get the index of all the characters of the alphabet
            // starting from the beginning of the String.
            int a = str.lastIndexOf("a", str.length() - 1);
            int b = str.lastIndexOf("b", str.length() - 1);
            int c = str.lastIndexOf("c", str.length() - 1);
            int d = str.lastIndexOf("d", str.length() - 1);
            int e = str.lastIndexOf("e", str.length() - 1);
            int f = str.lastIndexOf("f", str.length() - 1);
            int g = str.lastIndexOf("g", str.length() - 1);
            int h = str.lastIndexOf("h", str.length() - 1);
            int i = str.lastIndexOf("i", str.length() - 1);
            int j = str.lastIndexOf("j", str.length() - 1);
            int k = str.lastIndexOf("k", str.length() - 1);
            int l = str.lastIndexOf("l", str.length() - 1);
            int m = str.lastIndexOf("m", str.length() - 1);
            int n = str.lastIndexOf("n", str.length() - 1);
            int o = str.lastIndexOf("o", str.length() - 1);
            int p = str.lastIndexOf("p", str.length() - 1);
            int q = str.lastIndexOf("q", str.length() - 1);
            int r = str.lastIndexOf("r", str.length() - 1);
            int s = str.lastIndexOf("s", str.length() - 1);
            int t = str.lastIndexOf("t", str.length() - 1);
            int u = str.lastIndexOf("u", str.length() - 1);
            int v = str.lastIndexOf("v", str.length() - 1);
            int w = str.lastIndexOf("w", str.length() - 1);
            int x = str.lastIndexOf("x", str.length() - 1);
            int y = str.lastIndexOf("y", str.length() - 1);
            int z = str.lastIndexOf("z", str.length() - 1);

            // Display the results of all the lastIndexOf method calls.
            System.out.println(" a  b c  d  e  f  g  h i  j");
            System.out.println("===========================");
            System.out.println(a + " " + b + " " + c + " " + d + " " +
                               e + " " + f + " " + g + " " + h + " " +
                               i + " " + j + "\n");

            System.out.println("k  l  m  n  o  p q  r  s  t");
            System.out.println("===========================");
            System.out.println(k + " " + l + " " + m + " " + n + " " +
                               o + " " + p + " " + q + " " + r + " " +
                               s + " " + t + "\n");

            System.out.println(" u  v  w  x  y  z");
            System.out.println("=================");
            System.out.println(u + " " + v + " " + w + " " + x + " " +
                               y + " " + z);
    }

}

GetUnicodeOfAnCharacter

import java.util.Scanner;

public class GetUnicodeOfAnCharacter {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String a=sc.next();
System.out.println("the original string is:"+a);
int val1=a.codePointAt(0);
int val2=a.codePointAt(12);
System.out.println("Character(unicode) is:"+val1);
System.out.println("Character(unicode) is:"+val2);
    }

}

GivenTwoStringRotationOfEachOther

import java.util.Scanner;

public class GivenTwoStringRotationOfEachOther {
static boolean checkrotation(String a,String b) {
    return (a.length()==b.length())&&((a+a).indexOf(b)!=-1);
}
    public static void main(String[] args) {
        // TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String a=sc.next();
String b=sc.next();
System.out.println("The given strings are: "+a+"  and  "+b);
System.out.println("\nThe concatination of 1st string twice is: "+a+a);
if(checkrotation(a,b)) {
      System.out.println("The 2nd string "+b+"  exists in the new string.");    
      System.out.println("\nStrings are rotations of each other");
}
else {
    System.out.println("The 2nd string "+b+"  not exists in the new string.");  
    System.out.printf("\nStrings are not rotations of each other");
}
    }

}

LengthOfAGivenString

import java.util.Scanner;

public class LengthOfAGivenString {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String a=sc.next();
int len=a.length();
System.out.println("teh length of "+a+" is:"+len);
    }

}

PermutationsOfASpecifiedStringWithRepetition

public class PermutationsOfASpecifiedStringWithRepetition {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
PermutationWithRepeation("PQR");
    }
    private static void PermutationWithRepeation(String a) {
        System.out.println("The given string is: PQR");
          System.out.println("The permuted strings are:");
          showPermutation(a, "");
    }
    private static void showPermutation(String str1, String NewStringToPrint) {

          if (NewStringToPrint.length() == str1.length()) {
           System.out.println(NewStringToPrint);
           return;
          }
          for (int i = 0; i < str1.length(); i++) {

           showPermutation(str1, NewStringToPrint + str1.charAt(i));
          }

}
}

PrintAfterRemovingDuplicatesFromAGivenString

import java.util.Scanner;

public class PrintAfterRemovingDuplicatesFromAGivenString {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc=new Scanner(System.in);
        String a=sc.next();
        System.out.println("the original string is:"+a);
        System.out.println("the removed duplicate elements is:"+removeduplicates(a));
    }
    private static String removeduplicates(String a) {
        char b[]=a.toCharArray();
        String c="";
        for(char d:b) {
            if(c.indexOf(d)==-1) {
                c+=d;
            }
        }
        return c;
    }

}

PrintCurrentDateAndTimeInTheSpecifiedFormat

import java.util.Calendar;

public class PrintCurrentDateAndTimeInTheSpecifiedFormat {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
Calendar c=Calendar.getInstance();
System.out.println("Current Date and Time :");
System.out.format("%tB %te, %tY%n", c, c, c);
System.out.format("%tl:%tM %tp%n", c, c, c);
    }

}

RemoveBAndACFromGivenString

import java.util.Arrays;

public class RemoveBAndACFromGivenString {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
String a="abrambabasc";
System.out.println("the given string is:"+a);
System.out.println("after removing the new string is:");
removeString(a,"ac","b");
    }

    public static void removeString(String a,String b,String c) {
        int n=a.length();
        int ptr=0;
        char d[]=a.toCharArray();
        for(int i=0;i<n;i++) {
            if(d[i]=='b')
                continue;
            else if(i+1<n&&d[i]=='a'&&d[i+1]=='c')
                ++i;
            else
                d[ptr++]=d[i];//copy char to head
        }
        char e[]=Arrays.copyOfRange(d, 0, ptr);
        System.out.println(new String(e));
    }
   
}

RemoveDuplicateCharactersFromAGivenStringPresentsInAnotherGivenString

public class RemoveDuplicateCharactersFromAGivenStringPresentsInAnotherGivenString {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
String a="the quick brown box";
String b="queen";
char c[]=new char[a.length()];
char d[]=new char[256];
for(int i=0;i<b.length();i++)
    d[b.charAt(i)]++;
    System.out.println("the original string is:");
    for(int i=0;i<a.length();i++) {
        if(d[a.charAt(i)]==0)
            System.out.print(a.charAt(i));
    }

    }

}

ReplaceInSubString

import java.util.Scanner;

public class ReplaceInSubString {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String a=sc.next();
String c=sc.next();
String b=a.replace(a,c );
System.out.println("the original string is:"+a);
System.out.println("the replaced string is:"+b);
    }

}

ReplaceSpecifiedCharacterWithAnotherCharacter

import java.util.Scanner;

public class ReplaceSpecifiedCharacterWithAnotherCharacter {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String a=sc.next();
String b=a.replace('a', 'm');
System.out.println("the original string is:"+a);
System.out.println("the updated string is:"+b);
    }

}

ReverseAEveryWordInAString

public class ReverseAEveryWordInAString {
public void reverseWord(String a) {
    String b[]=a.split(" ");
    String c="";
    for(int i=0;i<b.length;i++) {
        String d=b[i];
        String e="";
        for(int j=d.length()-1;j>=0;j--) {
            e+=d.charAt(j);
        }
        c+=e+" ";
    }
    System.out.println(c);
}
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        ReverseAEveryWordInAString obj=new ReverseAEveryWordInAString();
        String a="this is a test string";
        System.out.println("the given string is:"+a);
        System.out.println("the string reversed word by word is:");
        obj.reverseWord(a);
    }

}

ReverseAStringInNormalMethod

import java.util.Scanner;

public class ReverseAStringInNormalMethod {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String a=sc.next();
for(int i=a.length()-1;i>0;i--) {
    System.out.print(a.charAt(i)+" ");
   
}
    }

}

ReverseAStringUsingRecurrsion

import java.util.Scanner;

public class ReverseAStringUsingRecurrsion {
void reversestring(String a) {
    if((a==null)||(a.length()<=1))
        System.out.println(a);
    else
        System.out.print(a.charAt(a.length()-1));
    reversestring(a.substring(0,a.length()-1));
}

    public static void main(String[] args) {
        // TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String a=sc.next();
System.out.println("the given string is:"+a);
System.out.println("the reverse orders string is:");
ReverseAStringUsingRecurrsion obj=new ReverseAStringUsingRecurrsion();
obj.reversestring(a);
    }

}

ReverseAStringUsingStringBuilder

public class ReverseAStringUsingStringBuilder {
public static String reverseString(String a) {
    StringBuilder b=new StringBuilder(a);
    String rev=b.reverse().toString();
    String c[]=rev.split(" ");
    StringBuilder reverse=new StringBuilder();
    for(String d:c) {
        b=new StringBuilder(d);
        reverse.append(b.reverse()+" ");
    }
    reverse.deleteCharAt(reverse.length()-1);
    return reverse.toString();
}
    public static void main(String[] args) {
        // TODO Auto-generated method stub
String a="Reverse the given word using the stringbuffer and reverse method";
System.out.println("the original string is:"+a);
System.out.println("the reversed  string is:"+reverseString(a));
    }

}

SubStringOfAString

import java.util.Scanner;

public class SubStringOfAString {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String a=sc.next();//obulipurusothaman
String b=a.substring(0, 5);
System.out.println("the original string is:"+a);
System.out.println("the sub string is:"+b);
    }

}

TestAGivenStringContainsSpecifiedSequenceOfCharValues

import java.util.Scanner;

public class TestAGivenStringContainsSpecifiedSequenceOfCharValues {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String a=sc.next();
String b=sc.next();
System.out.println("the string is:"+a);
System.out.println("its contains:"+a.contains(b));
    }

}

TrimWhiteSpaceFromTheString

import java.util.Scanner;

public class TrimWhiteSpaceFromTheString {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

String a="    OBULIPURUSOTHAMAN      ";
String b=a.trim();
System.out.println("the original string is:"+a);
System.out.println("the trimmed string is:"+b);
    }

}

UnicodeBeforeTheSpecifiedIndexInTheString

import java.util.Scanner;

public class UnicodeBeforeTheSpecifiedIndexInTheString {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String a=sc.next();
int val1=a.codePointBefore(1);
int val2=a.codePointBefore(10);
System.out.println("Character(unicode) is:"+val1);
System.out.println("Character(unicode) is:"+val2);
    }

}

UnicodePointInSpecifiedTextRange

import java.util.Scanner;

public class UnicodePointInSpecifiedTextRange {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String a=sc.next();
int val=a.codePointCount(0, 16);
System.out.println("Codepoint count is:"+val);
    }

}

Post a Comment

Previous Post Next Post