Software Development Exam  >  Software Development Notes  >  Basics of Java  >  Code: String Patterns

Code: String Patterns | Basics of Java - Software Development PDF Download

Code: String Patterns | Basics of Java - Software Development

1. Write a python program to print following character pattern: 

Code: String Patterns | Basics of Java - Software Development

public class CharacterPattern

{

   public static void main(String[] args) 

   {

      int n=5; 

      for(int i=1; i<=n; i++){

        for(int j=1; j<=i; j++){

           System.out.print("A ");

        }

        System.out.println();

     }

  } 

}

2. Write a python program to print following pattern: 

Code: String Patterns | Basics of Java - Software Development

public class CharacterPattern

{

   public static void main(String[] args) 

   {

      int n=5;

      for(int i=1, p='A'; i<=n; i++, p++){

        for(int j=1; j<=i; j++){

          System.out.print((char)p+"");

        }

        System.out.println();

     }

  }

}

3. Write a python code to print following character pattern: 

Code: String Patterns | Basics of Java - Software Development

public class CharacterPattern

{

   public static void main(String[] args) 

   {

      int n=5;

      for(int i=1, p='E'; i<=n; i++, p+=2){

        for(int j=1; j<=i; j++){

           System.out.print((char)p+"");

        }

        System.out.println();

      }

   }

}

4. Write a python code to print following pattern: 

Code: String Patterns | Basics of Java - Software Development

public class CharacterPattern 

    public static void main(String[] args) 

    { 

       int n=5;

       for(int i=1, p='E'; i<=n; i++, p--){

         for(int j=1; j<=i; j++){  

           System.out.print((char)p+"");

         }

         System.out.println();

       } 

   }

}

5. Write a python program to print following character pattern: 

Code: String Patterns | Basics of Java - Software Development

public class CharacterPattern

{

  public static void main(String[] args) 

  {

     int n=5;

     for(int i=1; i<=n;i++){

       int p=5;

       for(int j=1; j<=i; j++){

         if(i%2==0)

           System.out.print("0 ");

         else

           System.out.print("Z ");

       }

       System.out.println();

     }

   }

}

6. Write a python program to print following Dimond character pattern: 

Code: String Patterns | Basics of Java - Software Development

public class CharacterPattern

{

   public static void main(String[] args) 

   {

     int n= 5;

     for(int i=1, p= 'A'; i<=n; i++, p++){

       for(int j=i; j<=n; j++){

         System.out.print(" ");

       }

       for(int j=1; j<i; j++){

         System.out.print((char)p +" ");

       }

       for(int j=1; j<=i; j++){

         System.out.print((char)p +" ");

       }

       System.out.println();

    }

    for(int i=1, p='E'; i<=n; i++, p--){

      for(int j=1; j<=i; j++){

        System.out.print(" ");

      }

      for(int j=i; j<n; j++){

        System.out.print((char)p +" ");

      }

      for(int j=i; j<=n; j++){

        System.out.print((char)p +" ");

      }

      System.out.println();

    }

  }

}

7. Write a python program to print following character pattern: 

Code: String Patterns | Basics of Java - Software Development

public class CharacterPattern

{

  public static void main(String[] args)

  {

    int n= 5,p='A;

    for(int i=1; i<n; i++, p++){

      for(int j=i; j<=n; j++){

        System.out.print(" ");

      }

      for(int j=1; j<i; j++){

        System.out.print((char)p +" ");

      }

      for(int j=1; j<=i; j++){

        System.out.print((char)p +" ");

      }

      System.out.println();

    }

    for(int i=1; i<=n; i++, p++){

      for(int j=1; j<=i; j++){

        System.out.print(" ");

      }

      for(int j=i; j<n; j++){

        System.out.print((char)p +" ");

      }

      for(int j=i; j<=n; j++){

        System.out.print((char)p +" ");

      }

      System.out.println();

    }

  }

}

8. Write a python code to print Dimond pattern with character: 

Code: String Patterns | Basics of Java - Software Development

public class CharacterPattern

{

   public static void main(String[] args) 

   {

      int n=5;

      for(int i=1; i<=n; i++){

        int p='A';

        for(int j=1; j<=i; j++){

          System.out.print((char)p++ +" ");

        }

        System.out.println();

     }

  }

}

9. Write a python code to print following character pattern : 

Code: String Patterns | Basics of Java - Software Development

public class CharacterPattern

{

   public static void main(String[] args) 

   {

      int n= 5;

      for(int i=1; i<=n; i++){

        int p ='A';

        for(int j=1; j<=i; j++){

          System.out.print(" ");

        }

        for(int j=i; j<=n; j++){

          System.out.print((char)p++ +" ");

        }

        System.out.println();

     }

  }

}

10. Write a python code to print hill pattern with character:

Code: String Patterns | Basics of Java - Software Development 

public class CharacterPattern 

   public static void main(String[] args) 

   {  

      int n= 5; 

      for(int i=1; i<=n; i++){ 

         int p ='A'; 

         for(int j=i; j<=n; j++){    

            System.out.print(" "); 

         } 

         for(int j=1; j<i; j++){ 

            System.out.print((char)p++ +" "); 

         } 

         for(int j=1; j<=i; j++){ 

            System.out.print((char)p++ +" "); 

         } 

         System.out.println(); 

      } 

   } 

}

The document Code: String Patterns | Basics of Java - Software Development is a part of the Software Development Course Basics of Java.
All you need of Software Development at this link: Software Development
60 videos|37 docs|12 tests

Up next

60 videos|37 docs|12 tests
Download as PDF

Up next

Explore Courses for Software Development exam
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Previous Year Questions with Solutions

,

mock tests for examination

,

Important questions

,

Extra Questions

,

Exam

,

pdf

,

Free

,

practice quizzes

,

Code: String Patterns | Basics of Java - Software Development

,

shortcuts and tricks

,

Code: String Patterns | Basics of Java - Software Development

,

video lectures

,

Objective type Questions

,

Semester Notes

,

Code: String Patterns | Basics of Java - Software Development

,

Viva Questions

,

Sample Paper

,

study material

,

past year papers

,

Summary

,

MCQs

,

ppt

;