ICSE PROGRAMS ON STRING MANIPULATION IN JAVA PART - II - SELINA PUBLICATIONS BOOK SOLUTIONS


STRING MANIPULATIONS IN JAVA PART-II


/** Write a program to input a string. Convert it into upper case.  Count and output the numberof
double letter sequences that exists in the string
 Sample i/p: SHE WAS FEEDING THE LITTLE RABBIT WITH AN APPLE.
Sample o/p: 4                   **/
import java.util.*;
public class Q28
{
    public static void main(String args[])
    {           
                int c=0;
                System.out.println("\f");
                Scanner sc=new Scanner(System.in);
                System.out.println("enter a string");
                String st=sc.nextLine();
                st=st.toUpperCase();
                for(int i=0;i<st.length()-1;i++)
                {
                                if(st.charAt(i)==st.charAt(i+1))
                                c++;
                }
                System.out.println(c);
    }
}
/**
BLUEJ
BLUE
BLU
BL
B
 */
public class Q29A
{
    public static void main(String args[])
    {
                System.out.println("\f");
                String str="BLUEJ";
                int n=str.length();
                for(int i=n;i>=0;i--)
                {
                                System.out.println(str.substring(0,i));
                }
    }
}


/**
J
E  E
U U U
L  L   L  L
B  B  B  B  B
 */
public class Q29B
{
   public static void main(String args[])
   {
                String str="BLUEJ";
                int n=str.length();
                int k=0;
                for(int i=4;i>=0;i--)
                {
                                for(int j=0;j<=k;j++)
                                {
                                       System.out.print(str.charAt(i));
                                }
                                 System.out.println();
                                k++;
                }
   }
}
/**
BLUEJ
LUEJ
UEJ
EJ
J
 */
public class Q29C
{
    public static void main(String args[])
    {
                String str="BLUEJ";
                int n,i,k=0;
                n=str.length();
                for(i=0;i<n;i++)
                {
                                System.out.println(str.substring(k,n));
                                k++;
                }
    }
}



/**
ABCDE
BCDE
CDE
DE
F
 */
import java.util.*;
public class Q30A
{
   public static void main(String args[])
   {
                System.out.println("\f");
                Scanner sc =new Scanner(System.in);
                System.out.println("enter how many steps:");
                 int n= sc.nextInt();
                char ch='A', ch1;
                for(int i=n;i>=0;i--)
                 {
                                ch1=ch;
                                for(int j=0;j<=i;j++)
                                {
                                           System.out.print(ch1);
                                           ch1++;
                                 }
                                System.out.println(" ");
                                ch++;
                }
   }
}
/**
A
BC
DEF
GHIJ
KLMNO
 */
public class Q30B
{
  public static void main(String args[])
  {
                char ch='A';
                for(int i=0;i<5;i++)
                {
                                 for(int j=0;j<=i;j++)
                                 {
                                                System.out.print(ch++);
                                }
                                System.out.println();
                }
  }
}
/**
 ABCDE
 ABCDA
 ABCAB
 ABABC
 AABCD
*/
public class Q30C
{
    public static void main(String args[])
    {
                System.out.println("\f");
                char ch='A',ch1;
                int i,j,k=0;
                for(i=4;i>=0;i--)
                {
                                ch='A';
                                for(j=0;j<=i;j++)
                                {
                                                System.out.print(ch++);
                                }
                                ch1='A';
                                for(j=1;j<=k;j++)
                                {
                                                System.out.print(ch1++);
                                }
                                System.out.println();
                                k++;
                }
    }  
}
/*
ABCDE
   BCDE
     CDE
        DE
           E
 */
public class Q30D
{
   public static void main(String args[])
   {
                System.out.println("\f");
                char ch='A';
                int k=0,n;
                for(int i=4;i>=0;i--)
                {
                                for(int j=0;j<k;j++)
                                {
                                          System.out.print("*");
                                }
                                for(int l=4;l>=l-i;l--)
                                {
                                          System.out.print(ch++);
                                }
                                System.out.println("");
                                 k++;
                }
   }
}
/**         Write a program to display the pattern
EDCBA
   EDCB
      EDC
        ED
          E
 */
public class Q30E
{
    public static void main(String args[])
    {
                System.out.println("\f");      
                char ch='E';
                int k=0,l=5;
                for(int i=5;i>0;i--)
                {
                                ch='E';
                                for(int j=0;j<k;j++)
                                {
                                                System.out.print("  ");
                                }
                                k++;
                                for(int j=l;j>0;j--)
                                {
                                                System.out.print(ch--);
                                }
                                l--;
                                System.out.println();
                }              
    }
}


 /** Write a program to display the pattern
         A
       AB
     ABC
  ABCD
ABCDE
 */
import java.util.*;
public class Q30F
{
    public static void main(String args[])
    {
                System.out.println("\f");  
                Scanner sc= new Scanner(System.in);
                System.out.println("Enter no of lines");
                int n=sc.nextInt();
                char ch='A';
                int k=n-1,l=0;
                for(int i=0;i<n;i++)
                {
                                ch='A';
                                for(int j=k;j>0;j--)
                                {
                                                System.out.print(" ");
                                }
                                k--;
                                for(int j=0;j<=l;j++)
                                {
                                                System.out.print(ch++);
                                }
                                l++;
                                System.out.println();
                }              
    }
}
/** Write a program to generate a triangle or an inverted triangle till n terms based upon user's
choice of triangle to be displayed.
Example 1
Sample input : Type1 for a triangle
                                Type2 for an Inverted Triangle
                                Enter your choice: 1
                                Enter the no of Terms:5
Sample Output:
           *****
             ****
               ***
                 **
                   *
Example 2
Sample input : Type1 for a triangle
                                Type2 for an Inverted Triangle
                                Enter your choice: 2
                                Enter the no of Terms:5   
Sample Output:
                ABCDE
                ABCD
                ABC
                AB
                A                             */
import java.util.*;
public class Q31
{
    public static void main(String args[])
    {
             System.out.println("\f");  
             int n;
             Scanner sc= new Scanner(System.in);
             System.out.println("Type 1 for triangle\nType 2 for Inverted Triangle\nEnter your Choice: ");
             int choice=sc.nextInt();       
             switch(choice)
             {
                                case 1:  System.out.println("Enter no of terms:");
                                                n=sc.nextInt();
                                                int k=0,l=5;
                                                for(int i=0;i<n;i++)
                                                {
                                                                for(int j=0;j<=k;j++)
                                                                 {
                                                                                System.out.print(" ");
                                                                 }
                                                                 for(int j=l;j>0;j--)
                                                                {
                                                                                System.out.print("*");
                                                                }
                                                                k++;
                                                                l--;
                                                                System.out.println();
                                                }
                                                break;
                                case 2:  System.out.println("Enter no of terms:");
                                                n=sc.nextInt();
                                                 k=n;
                                                char ch='A';
                                                 for(int i=0;i<n;i++)
                                                {
                                                                ch='A';
                                                                 for(int j=0;j<k;j++)
                                                                {
                                                                                System.out.print(ch++);
                                                                }
                                                                 k--;
                                                                System.out.println();
                                                 }
                                                break;
                        default:       System.out.println("You entered a wrong choice");
        }
    }
}
/**Write a program to generate a triangle or an inverted triangle till n terms based upon user's choice of triangle to be displayed.
Example 1
Sample input : Type1 for a triangle
                                Type2 for an Inverted Triangle
                                Enter your choice: 1
                                Enter a word: BLUEJ
Sample Output:
           B
           L   L
          U   U  U
          E    E   E   E
          J    J   J    J    J
Example 2
input : Type1 for a triangle
Type2 for an Inverted Triangle
Enter your choice: 2
Enter a word: BLUEJ
Sample Output:
                BLUEJ
                BLUE
                BLU
                BL
                B                                             */
import java.util.*;
public class Q32
{
    public static void main(String args[])
    {
             System.out.println("\f");  
             int n;
             String st;
             Scanner sc= new Scanner(System.in);
             System.out.println("Type 1 for triangle\nType 2 for Inverted Triangle\nEnter your Choice: ");
             int choice=sc.nextInt();       
             switch(choice)
             {
                                case 1:  System.out.println("Enter a word :");
                                                st=sc.next();
                                                 n=st.length();
                                                int k=n-1,l=0;
                                                for(int i=0;i<n;i++)
                                                {
                                                                for(int j=0;j<=k;j++)
                                                                {
                                                                                System.out.print(" ");
                                                                }
                                                                k--;
                                                                for(int j=0;j<=l;j++)
                                                                {
                                                                                System.out.print(st.charAt(i));
                                                                }             
                                                                l++;
                                                                System.out.println();
                                                }
                                                break;
                                case 2:  System.out.println("Enter a word :");
                                                st=sc.next();
                                                n=st.length();                 
                                                for(int i=n;i>0;i--)
                                                {
                                                                System.out.println(st.substring(0,i));
                                                }
                                                break;
                          default:     System.out.println("You entered a wrong choice");
        }
    }
}
/**
BLUEJ
BLUE
BLU
BL
B
 */
public class Pattern1
{
    public static void main(String args[])
    {
                System.out.println("\f");
                String str="BLUEJ";
                 int n=str.length();
                for(int i=n;i>=0;i--)
                {
                                System.out.println(str.substring(0,i));
                }
    }
}

/*
 * B
 * BL
 * BLU
 * BLUE
 * BLUEJ
*/
public class Pattern2
{
  public static void main(String args[])
  {
                System.out.println("\f");
                String str="BLUEJ";
                 int i,n;
                n= str.length();
                for(i=0;i<=n;i++)
                {
                                System.out.println(str.substring(0,i));
                }
  } 
}
/**
BLUEJ
LUEJB
UEJBL
EJBLU
JBLUE
 */
public class Pattern3
{
  public static void main(String args[])
  {
                System.out.println("\f");
                String str="BLUEJ";
                int n,i;
                n=str.length();
                for(i=0;i<=n;i++)
                {
                                System.out.print(str.substring(i,n));
                                System.out.println(str.substring(0,i)+"\n");
                }
  }
}






/*
BLUEJ
  BLUE
    BLU
       BL
         B
 */
public class Pattern4
{
   public static void main(String args[])
   {
                System.out.println("\f");
                String str="BLUEJ";
                int k=0,n;
                n=str.length();
                for(int i=n;i>=0;i--)
                {
                                for(int j=0;j<k;j++)
                                {
                                        System.out.print(" ");
                                 }
                                System.out.println(str.substring(0,i));
                                k++;
                }
   }
}
/**
          B
        BL
      BLU
    BLUE
  BLUEJ

 */
public class Pattern5
{
    public static void main(String args[])
    {
                System.out.println("\f");
                String str="COMPUTER APPLICATION";
                int n= str.length();
                int k=n;
                for(int i=0;i<n;i++)
                {
                                for(int j=0;j<k;j++)
                                {
                                                System.out.print(" ");
                                }
                                System.out.println(str.substring(0,i));
                                k--;
                }
    }
}
/**
ABCDEF
GHIJK
LMNO
PQR
ST
U
 */
import java.util.*;
public class Pattern6
{
   public static void main(String args[])
   {
                System.out.println("\f");
                Scanner sc =new Scanner(System.in);
                System.out.println("enter how many steps:");
                int n= sc.nextInt();
                char ch='A';
                for(int i=n;i>=0;i--)
                {
                                 for(int j=0;j<=i;j++)
                                {
                                      System.out.print(ch);
                                      ch++;
                                }
                                System.out.println("\n");
                }
   }
}

Comments

  1. Please add happy word program

    ReplyDelete
  2. ISC Point is one of the best ISC Coaching Classes in Mumbai. ISC Point provides ISC Classes services in Mumbai, Borivali, Vile Parle.

    ________________________________________
    ISC Chemistry | ISC Biology | ISC Mathematics

    ReplyDelete

Post a Comment