The Programming Project: solved
Showing posts with label solved. Show all posts
Showing posts with label solved. Show all posts

Tuesday, September 21, 2021

ISC COMPUTER SCIENCE PRACTICAL SOLVED 2021 QUESTION 1: FASCINATING NUMBERS

 QUESTION 1:

A Fascinating number is one which when multiplied by 2 and 3 and then, after the results are concatenated with the original number, the new number contains all the digits from 1 to 9 exactly once. There can be any number of zeros and are to be ignored.

Example: 273

                273 x 1 = 273

                273 x 2 = 546

                273 x 3 = 819

Concatenating the results we get, 273546819 which contains all digits from 1 to 9 exactly once.

Thus, 273 is a Fascinating number.

Accept two positive integers m and n, where m must be less than n and the values of both ‘m’ and ‘n’ must be greater than 99 and less than 10000 as user input. Display all Fascinating numbers that are in the range between m and n (both inclusive) and output them along with the frequency , in the format given below:

 

Test your program with the following data and some random data:

Example 1

INPUT                   m = 100

                                 n = 500

OUTPUT: THE FASCINATING NUMBERS ARE:

                192  219  273  327

                FREQUECNY OF FASCINATING NUMBERES IS: 4

Example 2

INPUT                   m = 900

                                 n = 5000

OUTPUT: THE FASCINATING NUMBERS ARE:

                1902  1920  2019  2190  2703  2730  3027  3270

                FREQUECNY OF FASCINATING NUMBERES IS: 8

Example 3

INPUT                   m = 400

                                 n = 900

OUTPUT: THE FASCINATING NUMBERS ARE:

                NIL

                FREQUECNY OF FASCINATING NUMBERES IS: 0

 

 import java.util.*;

public class ISC2021QUESTION1 {
       public static void main(String[] args) {
       int m,n;
       Scanner in = new Scanner(System.in);
       do {
        System.out.println("Enter the lower bound(m):");
        m = in.nextInt();
        System.out.println("Enter the upper bound(n):");
        n = in.nextInt();
       }while (m < 99 || n > 10000 || m < n); // conditions check
       Fascinating obj = new Fascinating(m,n);
       obj.generateFascinatingNumbers();
       in.close();
       }
}
class Fascinating {
    public void generateFascinatingNumbers() {
        System.out.println("THE FSCINATING NUMBERS ARE:");
        for (int i=m;i<=n;i++){
            if(isFascinating(i)==true) {
                System.out.println(" "+i+" ");
                frequency++;
            }
        }
        if(frequency==0) {
            System.out.println("NIL:");
            System.out.println("FREQUNCY OF THE FASCINATING NUMBERS IS:"+frequency);
        }
        else
            System.out.println("FREQUNCY OF THE FASCINATING NUMBERS IS:"+frequency);
    }
    private boolean isFascinating(int numb){
        int digitFrequency=0// local variable
        String temp = "";
        // concatenating the numbers as stated
        temp = Integer.toString(numb)+Integer.toString(numb*2)+Integer.toString(numb*3);
        // checking that the frequecny of each digit is 1 or not
        for(int j=0j < 9j++){ // running through digit 1 to 9
            digitFrequency = 0;
            flag = true;
            for(int i=0;i<temp.length();i++){
                if(check.charAt(j)==temp.charAt(i)){
                    digitFrequency++;
                }
            }
            if(digitFrequency != 1
                flag = false;
            if(flag==false
                break;
        }
        return (flag == false? false : true);
    }
    Fascinating(int mint n)    {
        this.n = n;
        this.m = m;
        frequency = 0;
    }
    private static String check = "123456789";
    private int n;
    private int m;
    private int frequency;
    private boolean flag;
}

 

Saturday, April 12, 2014

ISC Computer Science Practical Solved, 2011


/*Design a program which accepts your date of birth in dd mm yyyy format. Check whether the date entered is valid or not.
If it is valid, display "VALID DATE", also compute and display the day number of the year for the date of birth.
If it is invalid, display "INVALID DATE" and then terminate the program.
Testing of the program
Input: Enter your date of birth in dd mm yyyy format 05 01 2010
Output: VALID DATE 5
Input: Enter your date of birth in dd mm yyyy format 03 04 2010
Output: VALID DATE 93
Input: Enter your date of birth in dd mm yyyy format 34 06 2010
Output: INVALID DATE */
// ISC Computer Science 2011, Practicals