Posts

Showing posts from August, 2018

Swapping two String.

Image
Write a program to input two strings S1 and S2. Swap strings S1 and S2. Print the strings before and after strings before and after interchange.

Arranging String in alphabetical order.

Image
Write a program to input a string. Convert into uppercase. Print the string also print the same string after arranging each letter in alphabetical order. E.g. INPUT: COBOL   OUTPUT: BCLOO

Reversing a String

Image
Write a program to input a string(str). Reverse the string and store it in another string(rev). Print both the strings and also a message whether the strings are same or not.

Program to count frequency of "yes" or "YES" in string.

Image
Write a program to input a sentence. Count and print the occurrence/frequency of a word "yes" or "YES" from the String. SOURCE CODE import java.io.*; import java.util.*; public class YES_yes {     public static void main(String args[])     {         Scanner sc=new Scanner(System.in);         System.out.print("Enter a String    :");         String str=sc.nextLine();         int k=0;         str=str+" ";         String s="";         for(int i=0;i<str.length();i++)         {             char ch=str.charAt(i);             if(ch!=' ')             {                 s=s+ch;             }             else             {                  if(s.compareTo("yes")==0 || s.compareTo("YES")==0)                 {                     k++;                 }                 s="";             }         }         System.out.println("\n\n");         System.out.println(&