ISC 2015, Computer Practical Prog. 1

import java.io.*;
public class ISC_2015_1
{
public static void main() throws IOException
{
InputStreamReader x = new InputStreamReader(System.in);
BufferedReader y = new BufferedReader(x);
int n,m;
int i,temp,s,c,r;
System.out.println(“Enter the value of M”);
m=Integer.parseInt(y.readLine());
System.out.println(“Enter the value of N”);
n=Integer.parseInt(y.readLine());

// validation
if(n>100 || (m<100 || m>10000))
{
System.out.println(“INVALID INPUT”);
System.exit(0);
}

else
{
for(i=m+1; ;i++)
{
temp=i;
c=0; s=0;
while(temp>0)
{
r=temp%10;
s=s+r;
temp=temp/10;
c++;
}
if(n==s)
{
System.out.println(“The required number = “+i);
System.out.println(“Total number of digits = “+c);
break;
}
}
}
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s