Page 546 - ComputerScience_Class_11
P. 546

SAMPLE PROJECTS                                           #Experiential Learning
                                                                                    #Coding & Computational Thinking
                                                                                    #Collaboration & Teamwork
                                                                                    #Communication



                Project   1    Write a program to covert a decimal number to other base and vice versa according to user’s
                               choice.
                               a. Decimal to Others

                                 1. Decimal to Binary
                                 2. Decimal to Octal
                                 3. Decimal to Hexadecimal
                               b. Others to Decimal
                                 1. Binary to Decimal

                                 2. Octal to Decimal
                                 3. Hexadecimal to Decimal
                 1       import java.util.*;

                 2       class Convert_between_Dec_others
                 3       {

                 4           int num,counter;
                 5           Convert_between_Dec_others()

                 6           {
                 7               num=0;

                 8               counter=0;
                 9           }

                10
                11           void dec2bin(int num)

                12           {
                13               int binaryVal[] = new int[32];
                14               int num1=num;

                15               while (num > 0)

                16               {
                17                   binaryVal[counter++] = num % 2;
                18                   num = num / 2;

                19               }
                20               System.out.print("Binary Value of " + num1 + " : " );

                21               for (int i = counter - 1; i >= 0; i--)




                  544  Touchpad Computer Science (Ver. 3.0)-XI
   541   542   543   544   545   546   547   548   549   550   551