Hello everyone ! This nice program will play a nice maths trick on you, leaving you bewildered for a short time and curious for the rest period, to know its formula. Instructions will be provided by the program itself. Enjoy another nice program by

**ICSE Java**.**Java Program :**

import java.io.*;

class trick

{

static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

static String garb;

static int s;

static void main()throws IOException

{

help();

input();

cal();

}

static void help()throws IOException

{

System.out.print("Welcome to Maths Magic.\n\nFor this trick, you need to think of a three digit number.");

System.out.print("\n\nEnter when you are ready : ");

garb=br.readLine();

System.out.print("\fNow subtract the sum of digits from the original number.\n\nEx.: If you select 943, then subtract (9 + 4 + 3) from 943");

System.out.print("\ni.e. 943 - (9 + 4 + 3) = 943 - 16 = 927.\n\nEnter when you are ready : ");

garb=br.readLine();

}

static void input()throws IOException

{

s=0;

System.out.print("\fNow enter any two of its digits, and I'll tell the third digit.\n\nEnter when you are ready : ");

garb=br.readLine();

try{

System.out.print("\nEnter 1st digit : ");

s=s+Integer.parseInt(br.readLine());

System.out.print("\nEnter 2nd digit : ");

s=s+Integer.parseInt(br.readLine());

}

catch(Exception e){

System.out.print("\nError. Please try again : ");

garb=br.readLine();

System.out.print("\f");

input();

}

}

static void cal()

{

int i;

for(i=0;i<=9;i++)

if((s+i)%9==0)

System.out.print("\nThe third digit is : "+i);

}

}

## No comments:

## Post a Comment