PYTHON STRING REVERSE def reverse(str): revstr="" for i in str: revstr=i+revstr print("reversed string is : ",revstr) string=input("Enter the string: ") print("Entered string is: ",string) reverse(string)
JAVA STRING ANAGRAM PROGRAM /* Exercise: An anagram is a word or a phrase made by transposing the letters of another word or phrase; for example, "parliament" is an anagram of "partial men" and "Software" is an anagram of "swear oft". Write a program that figures out whether ine string is an anagram of another string. The Program should ignore white space and punctuation. */ import java.util.*; import java.io.*; class demo { static boolean areAnagram(char []str1, char []str2) { int n1=str1.length; int n2=str2.length; //System.out.print(n1); if(n1!=n2) return false; Arrays.sort(str1); Arrays.sort(str2); for(int i=0; i<n1; i++) ...
JAVA STRING BYTE ARRAY OBJECT /* 6. WAP in Java to print the palindrome word from a sentence. */ import java.lang.*; import java.io.*; import java.util.*; class ReverseString { static void cal(String input) { //getBytes() method to convert string //into bytes[] byte strAsByteArray[]=input.getBytes(); byte result[]=new byte[strAsByteArray.length]; //store result in reverse order // into the result byte[] for (int i=0; i< strAsByteArray.length; i++) { result[i]=strAsByteArray[strAsByteArray.length-i-1]; } ...
JAVA STRING .REPLACE /* 5. WAP in Java to print when letters and corresponding frequency in a sentence. */ import java.util.*; class Test { public static void main(String args[]) { Scanner sc=new Scanner(System.in); String name; System.out.print("\nENTER ANY NAME: "); name=sc.nextLine(); String ns2=(name.charAt(0)+". "); String ns=""; int i=0,j=1; int sch=0; name.toLowerCase(); int len=name.length(); name.toLowerCase(); ...
JAVA STRING .EQUALS /* 4. WAP in Java to print the longest word in a sentence. If lengths are same then it will print the first word.*/ import java.util.*; class Test { public static void main(String args[]) { Scanner sc=new Scanner(System.in); String name; System.out.print("\nInput: "); name=sc.nextLine(); //System.out.print("NAME: "+name); String ns2=(name.charAt(0)+". "); String ls=""; int i=0; int lp=0,pi=-1,max=0,ival=0; ...