Sunday , 19 February 2017
Home » Class 12 » [Question 1] ISC 2015 Computer Practical Paper Solved

[Question 1] ISC 2015 Computer Practical Paper Solved

Click here to download the complete ISC 2015 Computer Science Paper 2 (Practical).


Given two positive numbers M and N, such that M is between 100 and 10000 and N is less than 100. Find the smallest integer that is greater than M and whose digits add up to N. For example, if M = 100 and N = 11, then the smallest integer greater than 100 whose digits add up to 11 is 119.

Write a program to accept the numbers M and N from the user and print the smallest required number whose sum of all its digits is equal to N. Also, print the total number of digits present in the required number. The program should check for the validity of the inputs and display an appropriate message for an invalid input.

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

Example 1

M = 100
N = 11

The required number = 119
Total number of digits = 3

Example 2

M = 1500
N = 25

The required number = 1699
Total number of digits = 4

Example 3

M = 99
N = 11


Example 4

M = 112
N = 130


Programming Code:

* The class Q1_ISC2015 inputs two integers 'm' and 'n' and prints smallest integer 
* greater than 'm' whose sum of digits is equal to 'n'
* @author :
* @Program Type : BlueJ Program - Java
* @Question Year : ISC Practical 2015 Question 1

import java.util.*;
class Q1_ISC2015
    int sumDig(long n) // Function to find sum of digits of a number
        int sum = 0, d;
            d = (int)(n%10);
            sum = sum + d;
            n = n/10;
        return sum;
    int countDig(long n) // Function to count the number of digits in a number
        String s = Long.toString(n);
        int len = s.length();
        return len;
    public static void main()throws Exception
        Q1_ISC2015 ob = new Q1_ISC2015();
        Scanner sc = new Scanner(;
        System.out.print("Enter a value of 'm' from 100 to 10000 : ");
        int m = sc.nextInt();
        System.out.print("Enter a value of n from 1 to 99 : ");
        int n = sc.nextInt();
        if(m<100 || m>10000 || n<1 || n>99)
            System.out.println("Invalid Input");
            long i = (long)m; // Required number can be out of range of 'int'
            /* The required number must be greater than 'm', 
               so loop will go on as long as that number is not obtained.*/
            System.out.println("The required number = "+i);
            System.out.println("Total number of digits = "+ob.countDig(i));


Enter a value of ‘m’ from 100 to 10000 : 1500
Enter a value of ‘n’ from 1 to 99 : 25
The required number = 1699
Total number of digits = 4

Enter a value of ‘m’ from 100 to 10000 : 100
Enter a value of ‘n’ from 1 to 99 : 20
The required number = 299
Total number of digits = 3

Enter a value of ‘m’ from 100 to 10000 : 112
Enter a value of ‘n’ from 1 to 99 : 130
Invalid Input

Check Also

[Question 2] ISC 2017 Computer Practical Paper Solved – Quiz Result

Solution of Program 2 of ISC 2017 Computer Science Paper 2 (Practical) Exam. Java program to input the answers of each participant row-wise and calculate their marks


  1. I did not use long….i did the program with int…will marks be deducted?

  2. sir will marks be deducted for not writing the comments???

  3. Sir,
    I’ve used the for loop to generate values from N till 15000 and calculated the sum of digits and checked if it was equal to N.The output came out perfectly,yet I have a doubt if 15000 is going cause any problem….?!

    • Yes, it may cause problem. Because for higher values of n, the required number could be more than 15000. But at the end, it all depends on the visiting examiner.

  4. I was able to execute this this program entirly right in the practical ISC and were also able to answer the viva questions.Thanks a lot….Sir

  5. I’m sure of scoring full marks in this paper…Kudos to your entire team for this vast repository of help for students…Great work…The Practical Tips helped me a lot…

  6. sir i attempted this question but i did not write the method for returning the no. of digits
    but my program is working perfectly on the computer with the given outputs in the specified format
    will there be some deductions??

  7. Sir, I have attempted the first program during the ISC Computer Science Practical Exam.I have solved the entire program within a single method, and have not included any main method in the program.Though the output has been flawless each time the program was executed, this makes me worry if I am to lose marks for making the program too simple, and not using any function or including the main method for execution.

  8. Sir, thanks a lot for posting a variety of practice questions on the site… helped me throughout last year and on the day of my ISC Practicals…!!
    // waiting for your expert comments on the theory exam coming our way.

  9. Sir, thank u for posting a variety of practice questions on the site……it helped me throughout last year and finally on the day of my ISC Practicals…!! // Sir, trust me when i say this : many computer students need a teacher like u

  10. Will marks be deducted if we have written the datatype of variable ‘i’ as int instead of long?


    This site is really very helpful. I owe my ability of solving java programs to this site.Because of continuous practice of programs i was able to execute my program successfully today in my isc practical exam.And the viva questions given in the notes section was also very helpul.
    Thank you very much.

  12. Sir, instead of using while as in “while(m<10000)" , I have used "for(i=m;;i++)" so that the loop may continue till infinity (even though it doesn't). And I have declared the methods to calculate sum and no. of digits as 'static' so that object doesn't need to be created.
    Is there any possibility that i m gonna loose marks…???

  13. will marks be deducted if we didn’t check for no’s which don’t add up to the number in the above program?

Leave a Reply to Shaunak Ghosh Cancel reply

Your email address will not be published. Required fields are marked *