Python,C,C++ and JAVA programs for CBSE, ISC, B.Tech and I.T Computer Science and MCA students

The Programming Project: ICSE JAVA PROGRAMS 2019: SECTION B QUESTION 5

Tuesday, December 29, 2020

ICSE JAVA PROGRAMS 2019: SECTION B QUESTION 5

 

ICSE Computer Applications Question Paper 2019 Solved for Class 10

 

Question 5.

Using the switch-case statement, write a menu driven program to do the following: [15]

(a)             To generate and print Letters from A to Z and their Unicode

Letters                               Unicode

  A                                          65

  B                                          66

   .                                           .

   .                                           .              

  Z                                          90

 

 

 

(b)             Display the following pattern using iteration (looping):

 

1

1         2

1    2        3

1    2        3        4

1    2        3        4       5

 

JAVA CODE

 

import java.util.*;

public class ICSEB5 {

       public static void main(String[] args) {

          Scanner input = new Scanner(System.in);

          int choice;

          System.out.println("Press 1 for Unicode and 2 for Pattern:");

          System.out.println("Please enter your choice:");

          choice = input.nextInt();

          switch(choice) {

          case 1:

                 unicodeLetters obj = new unicodeLetters();

                 obj.generateUnicode();

                 break;

          case 2:

                 numberPattern ob = new numberPattern();

                 ob.generatePattern();

                 break;

          default:

                 System.out.println("INVALID CHOICE:");

                 break;

          }

          input.close();

     }

}

class unicodeLetters {

       public void generateUnicode() {

              System.out.println("Letters                     Unicode");

              for(int i=65;i<=90;i++)

                     System.out.println((char)i+"                           "+i);

       }

}

class numberPattern {

       public void generatePattern() {

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

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

                           System.out.print(j+"   ");

                     System.out.println();

              }

       }

}

 




PYTHON CODE



class unicodeLetters:
    def generateUnicode(self):
        print("Letters          Unicode")
        for i in range(26):
            print((chr)(i+65),"        ",i+65)
class numberPattern:
    def generatePattern(self):
        for i in range(5):
            k=i+1
            for j in range(k):
                print(j+1end=" ")
            print()
print("Press 1 for Unicode and 2 for Pattern:")
choice = int(input("Please enter your choice:"))
if choice == 1:
    obj = unicodeLetters()
    obj.generateUnicode()
elif choice == 2:
    ob = numberPattern()
    ob.generatePattern()
else:
    print("INVALID INPUT")

No comments:

Post a Comment