Cool Number Guess Magic Trick Java Program (BlueJ Project)

By | October 24, 2016

Mind Reading Number Magic Trick

Years ago, I converted a beautiful math trick (all by myself) into a java program. By using this magic trick, the computer can tell which number the player has selected out of a hundred numbers, just after asking a few questions! Today, I am sharing this “Mind-Reading Number Magic Trick” with you guys out of generosity. I used BlueJ to compile and run these Java programs and I recommend you to do the same.

If you want a summary of what happens in this program, here it is. You are told to select a number between 1 and 99 in your mind. Then, the computer displays a small list of numbers and asks you whether your number is present in that list or not. It does not ask you to enter the number. It just requires you to say ‘Yes’ or ‘No’. Then the computer shows you another small list of numbers and again asks you if your number is present in that list or not. This is done several more times and then, the computer tells you which number you had selected in the very beginning in your mind, without ever asking you to enter the number itself! 8-) 8-) 8-) Cool, huh?

 


Purpose Of Creation

Some of you guys must be thinking, “Pfff… This is such an obvious trick. Why did this guy even bother implementing it in a Java program?!”. Well, here are some of the reasons for which I have created this Java project on my blog:

  • To give an idea to new students learning Java about how creative one can become in their programs and that almost any Java project topic can be successfully made if one wants to.
  • To provide a self-help example to people as to how a math magic trick can be implemented into a simple Java program.
  • To supply class X (10th standard) or class XII (12th standard) ICSE, CBSE, HSC, etc. students (especially in India) an amazing ready-made Java project source code for free.
  • To distribute this “Math Magic Number Guess Mind Reading Trick” Java project to any other class’ or standard’s students who are in any way related to Java.

And please know, that just like my previous Java project published on this blog (Hand Cricket Project In Java), I am allowing you all to use/download this project source code for free. This is also a “free royalty free project” made solely by me. So, you do not have to bother giving me any credits at all for this brilliant piece of work! :D :D :D

 


Input Code (Source Code):

// Program written by The Adarsh Mehta
// www.theadarshmehta.in

import java.io.*;
public class Cool_Number_Guess_Magic_Trick
{
    public static void main(String args[])throws IOException
    {
        int b=0; // to add the first numbers of each list of numbers in which the player's number is present, so as to arrive at the original number that the user entered in the beginning;
        int infinity=1; // used to keep the game running forever unless the player decides to end it;
        String checker=""; // to check if the user wants to keep playing this game or wants to exit;
        String a=""; // accepting the first input from the player (Yes or No);
        String c=""; // accepting the second input from the player (Yes or No);
        String d=""; // accepting the third input from the player (Yes or No);
        String e=""; // accepting the fourth input from the player (Yes or No);
        String f=""; // accepting the fifth input from the player (Yes or No);
        String g=""; // accepting the sixth input from the player (Yes or No);
        String h=""; // accepting the seventh input from the player (Yes or No);

        /* After referring to all the comments mentioned above,
         * you must be able to understand the working of this program as it is very easy.
         * If you find it complicated,
         * feel free to visit www.theadarshmehta.in
         * and contact The Adarsh Mehta.
         * Have fun!
         */

        InputStreamReader isr=new InputStreamReader(System.in);
        BufferedReader br=new BufferedReader(isr);
        while(infinity>0)
        {
            b=0;
            // This variable has been given its default value once again to avoid any issues;
            System.out.println("Yo!!!");
            System.out.println("Here's a Cool Number Trick which tells you which number you have selected out of a hundred numbers!!!");
            System.out.println("");
            System.out.println("####################");
            System.out.println("");
            System.out.println("INSTRUCTIONS:");
            System.out.println("You will be Asked 7 'Yes-No' Questions.");
            System.out.println("If your Answer is Yes, type 1 or Yes.");
            System.out.println("And If your Answer is No, type 0 or No.");
            System.out.println("Please do not enter any other input or else it might cause some unexpected errors.");
            System.out.println("");
            System.out.println("####################");
            System.out.println("");
            System.out.println("Choose a Number Between 1 and 99 and keep it in your mind.");
            System.out.println("");
            System.out.println("Below is a list of numbers. Is your number here?");
            System.out.println("2,   3,   6,   7,   10,");
            System.out.println("11,  14,  15,  18,  19,");
            System.out.println("22,  23,  26,  27,  30,");
            System.out.println("31,  34,  35,  38,  39,");
            System.out.println("42,  43,  46,  47,  50,");
            System.out.println("51,  54,  55,  58,  59,");
            System.out.println("62,  63,  66,  67,  70,");
            System.out.println("71,  74,  75,  78,  79,");
            System.out.println("82,  83,  86,  87,  90,");
            System.out.println("91,  94,  95,  98,  99,");
            System.out.println("Type Your Answer");
            System.out.println("");
            a=br.readLine();
            if(a.equalsIgnoreCase("Yes")||a.equalsIgnoreCase("Yes.")||a.equals("1")||a.equals("1.")||a.equalsIgnoreCase(" Yes")||a.equalsIgnoreCase(" Yes.")||a.equalsIgnoreCase("Yes ")||a.equalsIgnoreCase("Yes. ")||a.equals(" 1")||a.equals(" 1.")||a.equals("1 ")||a.equals("1. "))
            {
                b=b+2;
            }
            else
            {
                b=b;
            }
            System.out.println("");
            System.out.println("");
            System.out.println("Is your number here?");
            System.out.println("4,  5,  6,  7,  12,  13,  14,");
            System.out.println("15,  20,  21,  22,  23,  28,  29,");
            System.out.println("30,  31,  36,  37,  38,  39,  44,");
            System.out.println("45,  46,  47,  52,  53,  54,  55,");
            System.out.println("60,  61,  62,  63,  68,  69,  70,");
            System.out.println("71,  76, 77,  78,  79,  84,  85,");
            System.out.println("86,  87,  92,  93,  94,  95,");
            System.out.println("Type Your Answer");
            System.out.println("");
            c=br.readLine();
            if(c.equalsIgnoreCase("Yes")||c.equalsIgnoreCase("Yes.")||c.equals("1")||c.equals("1.")||c.equalsIgnoreCase(" Yes")||c.equalsIgnoreCase(" Yes.")||c.equalsIgnoreCase("Yes ")||c.equalsIgnoreCase("Yes. ")||c.equals(" 1")||c.equals(" 1.")||c.equals("1 ")||c.equals("1. "))
            {
                b=b+4;
            }
            else
            {
                b=b;
            }
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("Is Your Number Here?");
            System.out.println("1,  3,  5,  7,  9,");
            System.out.println("11,  13,  15,  17,  19,");
            System.out.println("21,  23,  25,  27,  29,");
            System.out.println("31,  33,  35,  37,  39,");
            System.out.println("41,  43,  45,  47,  49,");
            System.out.println("51,  53,  55,  57,  59,");
            System.out.println("61,  63,  65,  67,  69,");
            System.out.println("71,  73,  75,  77,  79,");
            System.out.println("81,  83,  85,  87,  89,");
            System.out.println("91,  93,  95,  97,  99,");
            System.out.println("Type Your Answer");
            System.out.println("");
            d=br.readLine();
            if(d.equalsIgnoreCase("Yes")||d.equalsIgnoreCase("Yes.")||d.equals("1")||d.equals("1.")||d.equalsIgnoreCase(" Yes")||d.equalsIgnoreCase(" Yes.")||d.equalsIgnoreCase("Yes ")||d.equalsIgnoreCase("Yes. ")||d.equals(" 1")||d.equals(" 1.")||d.equals("1 ")||d.equals("1. "))
            {
                b=b+1;
            }
            else
            {
                b=b;
            }
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("Is Your Number Here?");
            System.out.println("16,  17,  18,  19,");
            System.out.println("20,  21,  22,  23,");
            System.out.println("24,  25,  26,  27,");
            System.out.println("28,  29,  30,  31,");
            System.out.println("48,  49,  50,  51,");
            System.out.println("52,  53,  54,  55,");
            System.out.println("56,  57,  58,  59,");
            System.out.println("60,  61,  62,  63,");
            System.out.println("80,  81,  82,  83,");
            System.out.println("84,  85,  86,  87,");
            System.out.println("88,  89,  90,  91,");
            System.out.println("92,  93,  94,  95,");
            System.out.println("Type Your Answer");
            System.out.println("");
            e=br.readLine();
            if(e.equalsIgnoreCase("Yes")||e.equalsIgnoreCase("Yes.")||e.equals("1")||e.equals("1.")||e.equalsIgnoreCase(" Yes")||e.equalsIgnoreCase(" Yes.")||e.equalsIgnoreCase("Yes ")||e.equalsIgnoreCase("Yes. ")||e.equals(" 1")||e.equals(" 1.")||e.equals("1 ")||e.equals("1. "))
            {
                b=b+16;
            }
            else
            {
                b=b;
            }
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("Is Your Number Here?");
            System.out.println("8,  9,  10,  11,");
            System.out.println("12,  13,  14,  15,");
            System.out.println("24,  25,  26,  27,");
            System.out.println("28,  29,  30,  31,");
            System.out.println("40,  41,  42,  43,");
            System.out.println("44,  45,  46,  47,");
            System.out.println("56,  57,  58,  59,");
            System.out.println("60,  61,  62,  63,");
            System.out.println("72,  73,  74,  75,");
            System.out.println("76,  77,  78,  79,");
            System.out.println("88,  89,  90,  91,");
            System.out.println("92,  93,  94,  95,");
            System.out.println("Type Your Answer");
            System.out.println("");
            f=br.readLine();
            if(f.equalsIgnoreCase("Yes")||f.equalsIgnoreCase("Yes.")||f.equals("1")||f.equals("1.")||f.equalsIgnoreCase(" Yes")||f.equalsIgnoreCase(" Yes.")||f.equalsIgnoreCase("Yes ")||f.equalsIgnoreCase("Yes. ")||f.equals(" 1")||f.equals(" 1.")||f.equals("1 ")||f.equals("1. "))
            {
                b=b+8;
            }
            else
            {
                b=b;
            }
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("Is Your Number Here?");
            System.out.println("32,  33,  34,  35,  36,  37,");
            System.out.println("38,  39,  40,  41,  42,  43,");
            System.out.println("44,  45,  46,  47,  48,  49,");
            System.out.println("50,  51,  52,  53,  54,  55,");
            System.out.println("56,  57,  58,  59,  60,  61,");
            System.out.println("62,  63,  96,  97,  98,  99,");
            System.out.println("Type Your Answer");
            System.out.println("");
            g=br.readLine();
            if(g.equalsIgnoreCase("Yes")||g.equalsIgnoreCase("Yes.")||g.equals("1")||g.equals("1.")||g.equalsIgnoreCase(" Yes")||g.equalsIgnoreCase(" Yes.")||g.equalsIgnoreCase("Yes ")||g.equalsIgnoreCase("Yes. ")||g.equals(" 1")||g.equals(" 1.")||g.equals("1 ")||g.equals("1. "))
            {
                b=b+32;
            }
            else
            {
                b=b;
            }
            System.out.println("");
            System.out.println("");
            System.out.println("");
            System.out.println("Is Your Number Here?");
            System.out.println("64,  65,  66,  67,  68,  69,");
            System.out.println("70,  71,  72,  73,  74,  75,");
            System.out.println("76,  77,  78,  79,  80,  81,");
            System.out.println("82,  83,  84,  85,  86,  87,");
            System.out.println("88,  89,  90,  91,  92,  93,");
            System.out.println("94,  95,  96,  97,  98,  99,");
            System.out.println("Type Your Answer");
            System.out.println("");
            h=br.readLine();
            if(h.equalsIgnoreCase("Yes")||h.equalsIgnoreCase("Yes.")||h.equals("1")||h.equals("1.")||h.equalsIgnoreCase(" Yes")||h.equalsIgnoreCase(" Yes.")||h.equalsIgnoreCase("Yes ")||h.equalsIgnoreCase("Yes. ")||h.equals(" 1")||h.equals(" 1.")||h.equals("1 ")||h.equals("1. "))
            {
                b=b+64;
            }
            else
            {
                b=b;
            }
            if(b<100)
            {
                System.out.println("");
                System.out.println("******************");
                System.out.println("******************");
                System.out.println("Your number is "+b);
                System.out.println("******************");
                System.out.println("******************");
                System.out.println("");
                System.out.println("If you wish to end this game, type 'exit' and hit enter, else, press any other key and hit enter...");
                checker=br.readLine();
                if(checker.equalsIgnoreCase("Exit")||checker.equalsIgnoreCase(" Exit")||checker.equalsIgnoreCase("Exit ")||checker.equalsIgnoreCase("Exit.")||checker.equalsIgnoreCase(" Exit.")||checker.equalsIgnoreCase("Exit. "))
                {
                    infinity=1;
                    System.out.print('\f');
                    System.out.println("Good Bye!");
                    break;
                }
                else
                {
                    System.out.print('\f');
                }

            }
            else
            {
                System.out.println("");
                System.out.println("You did not follow the instructions properly. :P");
                System.out.println("You tried to be oversmart. :P");
                System.out.println("");
                System.out.println("If you wish to end this game, type 'exit' and hit enter, else, press any other key and hit enter...");
                checker=br.readLine();
                if(checker.equalsIgnoreCase("Exit")||checker.equalsIgnoreCase(" Exit")||checker.equalsIgnoreCase("Exit ")||checker.equalsIgnoreCase("Exit.")||checker.equalsIgnoreCase(" Exit.")||checker.equalsIgnoreCase("Exit. "))
                {
                    infinity=1;
                    System.out.print('\f');
                    System.out.println("Good Bye!");
                    break;
                }
                else
                {
                    System.out.print('\f');
                }

            }
        }
    }
}

// Program written by The Adarsh Mehta
// www.theadarshmehta.in

Output:

Yo!!!
Here’s a Cool Number Trick which tells you which number you have selected out of a hundred numbers!!!

####################

INSTRUCTIONS:
You will be Asked 7 ‘Yes-No’ Questions.
If your Answer is Yes, type 1 or Yes.
And If your Answer is No, type 0 or No.
Please do not enter any other input or else it might cause some unexpected errors.

####################

Choose a Number Between 1 and 99 and keep it in your mind.

Below is a list of numbers. Is your number here?
2, 3, 6, 7, 10,
11, 14, 15, 18, 19,
22, 23, 26, 27, 30,
31, 34, 35, 38, 39,
42, 43, 46, 47, 50,
51, 54, 55, 58, 59,
62, 63, 66, 67, 70,
71, 74, 75, 78, 79,
82, 83, 86, 87, 90,
91, 94, 95, 98, 99,
Type Your Answer

1
Is your number here?
4, 5, 6, 7, 12, 13, 14,
15, 20, 21, 22, 23, 28, 29,
30, 31, 36, 37, 38, 39, 44,
45, 46, 47, 52, 53, 54, 55,
60, 61, 62, 63, 68, 69, 70,
71, 76, 77, 78, 79, 84, 85,
86, 87, 92, 93, 94, 95,
Type Your Answer

1

Is Your Number Here?
1, 3, 5, 7, 9,
11, 13, 15, 17, 19,
21, 23, 25, 27, 29,
31, 33, 35, 37, 39,
41, 43, 45, 47, 49,
51, 53, 55, 57, 59,
61, 63, 65, 67, 69,
71, 73, 75, 77, 79,
81, 83, 85, 87, 89,
91, 93, 95, 97, 99,
Type Your Answer

No

Is Your Number Here?
16, 17, 18, 19,
20, 21, 22, 23,
24, 25, 26, 27,
28, 29, 30, 31,
48, 49, 50, 51,
52, 53, 54, 55,
56, 57, 58, 59,
60, 61, 62, 63,
80, 81, 82, 83,
84, 85, 86, 87,
88, 89, 90, 91,
92, 93, 94, 95,
Type Your Answer

Yes

Is Your Number Here?
8, 9, 10, 11,
12, 13, 14, 15,
24, 25, 26, 27,
28, 29, 30, 31,
40, 41, 42, 43,
44, 45, 46, 47,
56, 57, 58, 59,
60, 61, 62, 63,
72, 73, 74, 75,
76, 77, 78, 79,
88, 89, 90, 91,
92, 93, 94, 95,
Type Your Answer

0

Is Your Number Here?
32, 33, 34, 35, 36, 37,
38, 39, 40, 41, 42, 43,
44, 45, 46, 47, 48, 49,
50, 51, 52, 53, 54, 55,
56, 57, 58, 59, 60, 61,
62, 63, 96, 97, 98, 99,
Type Your Answer

Yes.

Is Your Number Here?
64, 65, 66, 67, 68, 69,
70, 71, 72, 73, 74, 75,
76, 77, 78, 79, 80, 81,
82, 83, 84, 85, 86, 87,
88, 89, 90, 91, 92, 93,
94, 95, 96, 97, 98, 99,
Type Your Answer

No.

******************
******************
Your number is 54
******************
******************

If you wish to end this game, type ‘exit’ and hit enter, else, press any other key and hit enter…

exit

Good Bye!

 


Wrapping Up

If you want to run this program, just copy the source code (input code), paste it in BlueJ or any other similar software, compile it and then run it. You can even show this magic trick to small children and make their day! :) :) :)

As usual, comment below if you face any problems or have any doubts whatsoever. Also, I have not spent a lot of time on this program, so there is a tiny chance that it has some bug (I don’t think so, though). So, if you find any bugs or errors in this code, please comment below or contact me and I’ll do the needful.

Thank you.

LINK TO THIS POST:

<a href="https://www.theadarshmehta.in/blog/java-bluej-number-magic-trick-project-topic-with-source-code-10th-icse/2016/10">Cool Number Guess Magic Trick Java Program (BlueJ Project)</a>

Spread the love

34 thoughts on “Cool Number Guess Magic Trick Java Program (BlueJ Project)

  1. EKNOORPREET SINGH

    HEY BRO YOU HAVE DONE HARD WORK BUT THERE IS A MISTAKE WHEN I CHOOSE 14 NUMBER THE COMPILER GIVE ME ANSWER 10 PLEASE CONTACT ME I NEED IT FOR MY I C S E BOARD PROJECT AND IT IS VERY URGENT NEED HELP WITHIN TWO DAYS I AM COPYING YOUR PROGRAM FOR MY PROJECT PLEASE HELP ME THE PROJECT IS OF 50 MARKS

    Reply
  2. Gautham r

    Cool number magic trick is a very good program.Can any one post the flowchart and class design for this ?plss it’s quite important and urgent

    Reply
  3. Axel

    hey bro how can i open it in terminal window?
    i am a beginner in bluej please help………

    Reply
  4. manish

    Adarsh u create cool programs buddy..i needed some programs for project and i selected 2programs of yours which was very useful to me…
    Thank you friend

    Reply
  5. Arka Das

    hey man u cud have justr put 0-99 all the numbers….nothing special about it…how is it magic???it is simple programming just put0-99 useless program!!!!

    Reply
  6. RAGAVENDRA

    bro GOOD PROGRAM FOR BEST ASSIGNMENT YES YOU NUBER MAGIC TRICK IS MY ASSIGNMENT PL INTRODUCE SUM HOW DIFFRENT AFTER YOUR HAND CRICKET

    Reply
  7. vishva

    the program was just awesome!! and really very much beneficial!!
    but i have a question ….can you explain me the selection of number of evey list is different and why you have selected such numbers for a particular list??

    Reply
  8. Pranav

    Can i get the variable list for the above program
    IT IS VERY IMPORTANT BRO

    Reply
  9. Faisal Khan

    Bro can you please tell what is the use of
    System.out.println(‘\f’);

    \f ????

    plzz bro its impt

    Reply
  10. Kshaunish Shetty

    Thanks Adarsh.That’s indeed an awesome project.But can you explain me the logic in detail.

    Reply
  11. Himanshu Raj

    import mensuminia.triangle; import solidfig.cube;
    import mensuminia.circle; import solidfig.cuboid;
    import mensuminia.square; import solidfig.sphere;
    import mensuminia.rectangle; import solidfig.cone;
    import mensuminia.rhombus; import solidfig.cylinder;
    import java.io.*;
    public class mensumin
    {
    public void disp()throws IOException
    { int y=0;
    { for(int x=1;x>0;x++)
    {
    triangle tr=new triangle();
    cone co=new cone();
    cuboid cub=new cuboid();
    rhombus rh=new rhombus();
    circle ci=new circle();
    sphere sp=new sphere();
    cylinder cy=new cylinder();
    cube cu=new cube();
    square sq=new square();
    rectangle re=new rectangle();
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    System.out.println(“Welcome to our Computer Project”);
    System.out.println(“####################”);
    System.out.println(“”);
    System.out.println(“1. Plane Fig.”);
    System.out.println(“2. Solid Fig.”);
    System.out.println(“3. Exit”);
    System.out.println(“”);
    System.out.println(“Enter Your choice”);
    int l=Integer.parseInt(br.readLine());

    switch(l)
    { case 1: System.out.println(“You have selected the plane figure”);
    System.out.println(“”);
    System.out.println(“1. Triangle”);
    System.out.println(“2. Circle”);
    System.out.println(“3. Square”);
    System.out.println(“4. Rectangle”);
    System.out.println(“5. Rhombus”);
    System.out.println(“6. Back”);
    int a=Integer.valueOf(br.readLine());
    switch(a)
    {
    case 1:System.out.println(“You have selected the triangle”);
    System.out.println(“”);
    System.out.println(“####################”);
    System.out.println(“”);
    System.out.println(“1. Definition”);
    System.out.println(“2. Perimeter”);
    System.out.println(“3. Area”);
    System.out.println(“4. Back”);
    System.out.println(“”);
    int t=Integer.valueOf(br.readLine());
    switch(t)
    { case 1:
    System.out.println(tr.definition());
    break;
    case 2:
    System.out.println(“Perimeter”);
    System.out.println(“####################”);
    System.out.println(“1. Equilateral Triangle”);
    System.out.println(“2. Issoceles Triangle”);
    System.out.println(“3. Scalene Triangle”);
    System.out.println(“4. Right Angled Triangle”);
    System.out.println(“5. Back”);
    int w=Integer.valueOf(br.readLine());
    switch(w)
    { case 1:
    System.out.println(“Enter the length for a side”);

    double qq=Double.valueOf(br.readLine());
    System.out.println(“Perimeter “+tr.peri(qq,qq,qq));
    break;
    case 2: System.out.println(“Enter the length for the similar side”);

    double aqq=Double.valueOf(br.readLine());
    System.out.println(“Enter the length for 2nd side”);
    double pp=Double.valueOf(br.readLine());
    System.out.println(“Perimeter “+tr.peri(aqq,aqq,pp));
    break;
    case 3:
    System.out.println(“Enter side 1”);
    double qe=Double.valueOf(br.readLine());
    System.out.println(“Enter side 2”);
    double uu= Double.valueOf(br.readLine());
    System.out.println(“Enter side 3”);
    double yy=Double.valueOf(br.readLine());
    System.out.println(“Perimeter “+tr.peri(qe,uu,yy));
    break;
    case 4: System.out.println(“Enter the height”);
    double hh=Double.valueOf(br.readLine());
    System.out.println(“Enter the base”);
    double bb=Double.valueOf(br.readLine());
    double ho=Math.pow(hh*hh+bb*bb,0.5);
    System.out.print(“Perimeter “+tr.peri(hh,bb,ho));
    break;
    case 5:
    y=y+1;

    break;
    } break;
    case 3:
    System.out.println(“Area”);
    System.out.println(“####################”);
    System.out.println(“1. Equilateral Triangle”);
    System.out.println(“2. Issoceles Triangle”);
    System.out.println(“3. Scalene Triangle”);
    System.out.println(“4. Right Angled Triangle”);
    System.out.println(“5. Back”);
    int qw=Integer.valueOf(br.readLine());
    switch(qw)
    { case 1:
    System.out.println(“Enter the side”);
    double qa=Double.valueOf(br.readLine());
    System.out.println(“Area “+tr.Area(a,a,a));
    break;
    case 2:
    System.out.println(“Enter the side which is similar to the 2nd one”);

    double ea=Double.valueOf(br.readLine());
    System.out.println(“Enter the side 2”);
    double b=Double.valueOf(br.readLine());
    System.out.println(“Area “+tr.Area(a,a,b));
    break;
    case 3: System.out.println(“Enter the side 1”);
    double ta=Double.valueOf(br.readLine());
    System.out.println(“Enter the side 2”);
    double gb=Double.valueOf(br.readLine());
    System.out.println(“Enter the side 3”);
    double c=Double.valueOf(br.readLine());
    System.out.println(“Area “+tr.Area(ta,gb,c));
    break;
    case 4: System.out.println(“Enter the Height”);
    double h=Double.valueOf(br.readLine());
    System.out.println(“Enter the Base”);
    double ib=Double.valueOf(br.readLine());
    System.out.println(“Area “+0.5*h*ib);
    break;
    case 5:

    y=y+1;
    break;}
    break;
    case 4: y=y+1;
    break;
    } break;
    case 2: System.out.println(“You have selected the Circle”);
    System.out.println(“”);
    System.out.println(“####################”);
    System.out.println(“”);
    System.out.println(“1. Definition”);
    System.out.println(“2. Circumference”);
    System.out.println(“3. Area”);
    System.out.println(“4. Back”);
    System.out.println(“”);
    int lq=Integer.valueOf(br.readLine());
    switch(lq)
    { case 1:
    System.out.println(“Definition :- “+ci.definition());
    break;
    case 2:
    System.out.println(“Enter the Radius of the circle”);
    double r=Double.valueOf(br.readLine());
    System.out.println(“Circumference “+ci.peri(r));
    break;
    case 3:
    System.out.println(“Enter the Radius of the circle”);
    double qr=Double.valueOf(br.readLine());
    System.out.println(“Area “+ci.Area(qr));
    break;
    case 4:
    y=y+1;
    break;}
    break;
    case 3: System.out.println(“You have selected the Square”);
    System.out.println(“”);
    System.out.println(“####################”);
    System.out.println(“”);
    System.out.println(“1. Definition”);
    System.out.println(“2. Perimeter”);
    System.out.println(“3. Area”);
    System.out.println(“4. Back”);
    System.out.println(“”);
    int ls=Integer.valueOf(br.readLine());
    switch(ls)
    { case 1:
    System.out.println(“Definition :- “+sq.definition());
    break;
    case 2: System.out.println(“Enter the side “);
    double tqr=Double.valueOf(br.readLine());
    System.out.println(“Perimeter “+sq.peri(tqr));
    break;
    case 3: System.out.println(“Enter the side “);
    double trr=Double.valueOf(br.readLine());
    System.out.println(” Area “+sq.Area(trr));
    break;
    case 4:
    y=y+1;
    break;
    } break;
    case 4: System.out.println(“You have selected the Rectangle”);
    System.out.println(“”);
    System.out.println(“####################”);
    System.out.println(“”);
    System.out.println(“1. Definition”);
    System.out.println(“2. Perimeter”);
    System.out.println(“3. Area”);
    System.out.println(“4. Back”);
    System.out.println(“”);
    int sl=Integer.valueOf(br.readLine());
    switch(sl)
    { case 1:
    System.out.println(re.definition());
    break;
    case 2:System.out.println(“Enter the length”);
    double ll= Double.valueOf(br.readLine());
    System.out.println(“Enter the breadth”);
    double bb= Double.valueOf(br.readLine());

    System.out.println(re.peri(ll,bb));
    break;
    case 3: System.out.println(“Enter the length”);
    double li= Double.valueOf(br.readLine());
    System.out.println(“Enter the breadth”);
    double bi= Double.valueOf(br.readLine());

    System.out.println(re.Area(li,bi));
    break;
    case 4:
    y=y+1;
    break;
    } break;
    case 5: System.out.println(“You have selected the Rhombus”);
    System.out.println(“”);
    System.out.println(“####################”);
    System.out.println(“”);
    System.out.println(“1. Definition”);
    System.out.println(“2. Perimeter”);
    System.out.println(“3. Area”);
    System.out.println(“4. Back”);
    System.out.println(“”);
    int zl=Integer.valueOf(br.readLine());
    switch(zl)
    { case 1:
    System.out.println(rh.definition());
    break;
    case 2: System.out.println(“Enter the side “);
    double tar=Double.valueOf(br.readLine());
    System.out.println(rh.peri(tar));
    break;
    case 3: System.out.println(“Enter the base “);
    double bbr=Double.valueOf(br.readLine());
    System.out.println(“Enter the height “);
    double hhr=Double.valueOf(br.readLine());
    System.out.println(rh.Area(bbr,hhr));
    break;
    case 4: break;
    } break;
    case 6:
    y=y+1;
    break;
    }break;
    case 2: System.out.println(“You have selected the solid figure “);
    System.out.println(“”);
    System.out.println(“####################”);
    System.out.println(“”);
    System.out.println(“1. Cone”);
    System.out.println(“2. Sphere”);
    System.out.println(“3. Cube”);
    System.out.println(“4. Cuboid”);
    System.out.println(“5. Cylinder “);
    System.out.println(“6. Back”);
    int qw=Integer.valueOf(br.readLine());
    switch(qw)
    { case 1: System.out.println(“You have selected the Cone “);
    System.out.println(“”);
    System.out.println(“********************”);
    System.out.println(“”);
    System.out.println(“1. Definition”);
    System.out.println(“2. Slant Height”);
    System.out.println(“3. Volume”);
    System.out.println(“4. Curved Surface Area”);
    System.out.println(“5. Total Surface Area”);
    System.out.println(“6. Back”);

    int tuy=Integer.valueOf(br.readLine());
    switch(tuy)
    { case 1: System.out.println(“Definition :- “+co.definition());
    break;
    case 2: System.out.println(“You have selected the slant height”);
    System.out.println(“”);
    System.out.println(“Enter the radius”);
    double bhr=Double.valueOf(br.readLine());
    System.out.println(“Enter the height”);
    double hhh=Double.valueOf(br.readLine());
    System.out.println(“slant height “+co.slantheight(bhr,hhh));
    break;
    case 3: System.out.println(“”);
    System.out.println(“Enter the radius”);
    double rrr=Double.valueOf(br.readLine());
    System.out.println(“Enter the height”);
    double hdh=Double.valueOf(br.readLine());
    System.out.println(“Volume “+co.volume(rrr,hdh));
    break;
    case 4: System.out.println(“You have selected Curved Surface Area”);
    System.out.println(“”);
    System.out.println(“###################”);
    System.out.println(“Enter the radius”);
    double rpr=Double.valueOf(br.readLine());
    System.out.println(“Enter the slant height”);
    double shh=Double.valueOf(br.readLine());
    System.out.println(“Curved Surface Area “+co.curvedsa(shh,rpr));
    break;
    case 5: System.out.println(“Total Surface Area”);
    System.out.println(“”);
    System.out.println(“Enter the slant height”);
    double ssh=Double.valueOf(br.readLine());
    System.out.println(“Enter the radius”);
    double rrp=Double.valueOf(br.readLine());
    System.out.println( co.totalsa(ssh,rrp));
    break;
    case 6:
    y=y+1;
    break;

    }
    break;
    case 2:System.out.println(“You have selected Sphere”);
    System.out.println(“”);
    System.out.println(“###################”);
    System.out.println(“”);
    System.out.println(“1. Definition”);
    System.out.println(“2. Diameter “);
    System.out.println(“3. Circumference”);
    System.out.println(“4. Surface Area”);
    System.out.println(“5. Volume”);
    System.out.println(“6. Back”);
    int tty=Integer.valueOf(br.readLine());
    switch(tty)
    { case 1: System.out.println(sp.definition());
    break;
    case 2:
    System.out.println(“**Diameter**”);
    System.out.println(” Enter The Radius”);
    double rry= Double.valueOf(br.readLine());
    System.out.println(sp.diameter(rry));
    break;
    case 3: System.out.println(“** Circumference **”);
    System.out.println(” Enter The Radius”);

    double rrr=Integer.valueOf(br.readLine());
    System.out.println(sp.circumference(rrr));
    break;
    case 4:
    System.out.println(“** Surface Area **”);
    System.out.println(” Enter The Radius”);

    double rar=Integer.valueOf(br.readLine());
    System.out.println(sp.surfacearea(rar));
    break;
    case 5: System.out.println(“** Volume **”);
    System.out.println(” Enter The Radius”);

    double rjr=Double.valueOf(br.readLine());
    System.out.println(sp.volume(rjr));
    break;
    case 6:
    y=y+1;
    break;
    }
    break;
    case 3: System.out.println(“You have selected the Cube “);
    System.out.println(“”);
    System.out.println(“********************”);
    System.out.println(“”);
    System.out.println(“1. Definition”);
    System.out.println(“2. Total Surface Area”);
    System.out.println(“3. Volume of cube”);
    System.out.println(“4. Diagonal of face of cube”);
    System.out.println(“5. Diagonal of cube”);
    System.out.println(“6. Back”);
    int ds=Integer.valueOf(br.readLine());
    switch(ds)
    { case 1: System.out.println(cu.definition());
    break;
    case 2: System.out.println(“Enter the edge”);
    double qqa=Double.valueOf(br.readLine());
    System.out.println(cu.totals(qqa));
    break;
    case 3:System.out.println(“*** Volume of cube ******”);
    System.out.println(“Enter the edge”);
    qqa=Double.parseDouble(br.readLine());
    System.out.println(cu.volume(qqa));
    break;
    case 4:System.out.println(” Diagonal of face of cube”);
    System.out.println(“####################”);
    System.out.println(“Enter the edge”);
    qqa=Double.parseDouble(br.readLine());
    System.out.println(cu.diagonalfc(qqa));
    break;
    case 5:
    System.out.println(” Diagonal of cube”);
    System.out.println(“####################”);
    System.out.println(“Enter the edge”);
    qqa=Double.parseDouble(br.readLine());
    System.out.println(cu.diagonal(qqa));
    break;
    case 6: y=y+1;
    break;
    } break;
    case 4: System.out.println(“You have selected the Cuboid “);
    System.out.println(“”);
    System.out.println(“********************”);
    System.out.println(“”);
    System.out.println(“1. Definition”);
    System.out.println(“2. Total Surface Area “);
    System.out.println(“3. Volume”);
    System.out.println(“4. Perimeter”);
    System.out.println(“5. Back”);
    int dqs=Integer.valueOf(br.readLine());
    switch(dqs)
    { case 1: System.out.println(cub.definition());
    break;
    case 2: System.out.println(“Enter the length”);
    double kk=Double.valueOf(br.readLine());
    System.out.println(“Enter the breadth”);
    double bb=Double.valueOf(br.readLine());
    System.out.println(“Enter the height”);
    double hh=Double.valueOf(br.readLine());
    System.out.println(cub.totals(kk,bb,hh));
    break;
    case 3:
    System.out.println(“Enter the length”);
    double kl=Double.valueOf(br.readLine());
    System.out.println(“Enter the breadth”);
    double bu=Double.valueOf(br.readLine());
    System.out.println(“Enter the height”);
    double hd=Double.valueOf(br.readLine());
    System.out.println(cub.volume(kl,bu,hd));
    break;
    case 4: System.out.println(“Enter the length”);
    double kll=Double.valueOf(br.readLine());
    System.out.println(“Enter the breadth”);
    double bbf=Double.valueOf(br.readLine());
    System.out.println(“Enter the height”);
    double hha=Double.valueOf(br.readLine());
    System.out.println(cub.peri(kll,bbf,hha));
    break;
    case 5:
    y=y+1;
    break;
    } break;
    case 5: System.out.println(“You have selected the Cylinder “);
    System.out.println(“”);
    System.out.println(“********************”);
    System.out.println(“”);
    System.out.println(“1. Definition”);
    System.out.println(“2.Total Surface Area “);
    System.out.println(“3. Area”);
    System.out.println(“4. Back”);
    int qwe=Integer.valueOf(br.readLine());
    switch(qwe)
    {
    case 1: System.out.println(“Definition :- “+cy.definition());
    break;
    case 2: System.out.println(“Total Surface Area “);
    System.out.println(“********************”);
    System.out.println(“Enter the radius”);
    double rtp=Double.valueOf(br.readLine());
    System.out.println(“Enter the height”);
    double hgh=Double.valueOf(br.readLine());
    System.out.println(cy.totalsa(hgh,rtp));

    break;
    case 3:
    System.out.println(“Area”);
    System.out.println(“********************”);
    System.out.println(“Enter the radius”);
    double rtr=Double.valueOf(br.readLine());
    System.out.println(“Enter the height”);
    double hgg=Double.valueOf(br.readLine());
    System.out.println(cy.area(hgg,rtr));
    break;
    case 4:y=y+1;
    break;
    }
    case 6: y=y+1;
    break;
    }break;
    case 3:

    break;

    }

    if(l==3)
    break;
    if(y==0)
    { System.out.println(“”);
    System.out.println(“**********************”);
    System.out.println(“Do You want to continue yes/no “);
    String qaz=br.readLine();
    if(qaz.equalsIgnoreCase(“no”))
    break;
    else System.out.print(‘\f’);
    }
    else y=0;
    System.out.print(‘\f’);

    }}

    System.out.print(‘\f’);
    System.out.println(“”);
    System.out.println(“Good Bye”);
    System.out.println(” |————————————-| *”);
    System.out.println(” |Program by Himanshu Raj | *” );
    System.out.println(” |————————————-| *” );
    System.out.println(“******************************************”);
    }
    }

    Reply
    1. Himanshu Raj

      Icse project that we got in Class X this year
      i request the admin not to remove my comment
      pzzzzz

      Reply
      1. muniraju

        its not compiling at all . there are more mistakes in this program ,we get head ache if we go to compile this . its waste of time

        Reply
  12. Dhruv the Great

    Well this is a pretty cool trick
    Please explain the logic behind this trick – FROM DHRUV THE GREAT
    CHRIST THE KING COLLEGE

    Reply
    1. Swaroop.P.B

      it’s quiet simple…..see if your number is there in the given set of numbers then the first number of the given ste gets added up …
      example:
      8, 9, 10, 11,
      12, 13, 14, 15,
      24, 25, 26, 27,
      28, 29, 30, 31,
      40, 41, 42, 43,
      44, 45, 46, 47,
      56, 57, 58, 59,
      60, 61, 62, 63,
      72, 73, 74, 75,
      76, 77, 78, 79,
      88, 89, 90, 91,
      92, 93, 94, 95
      if ur number is in this then its first number i.e 8 will get added up ….then the final added ans will be ur guessed number okay naa…..

      Reply
  13. Vaibhav Chandra

    i am a beginner in java
    i program on bluej
    what was the strategy behind this program

    Reply
  14. Gokul Prabhakar

    That was a pretty AWESOME program!

    Did you really make that source code yourself????

    Reply
    1. Adarsh Mehta Post author

      Very much happy to hear these words brother! ^_^

      And yes, I did make this Java Program (the whole source code) ALL BY MYSELF, when I was in Class IX as far as I remember. :)

      Thank you.

      Reply
    1. Adarsh Mehta Post author

      Hello, Shashath.

      It is really simple.

      You have to go reverse to understand the simple working of this magic trick.

      Let’s say we make 3 lists. The user can select any number from 1 to 6:

      LIST 1:
      1, 3, 5

      LIST 2:
      2, 3, 6

      LIST 3:
      4, 5, 6

      Can you notice a pattern? We are using only 1, 2 and 4 to make up the numbers. So, let’s say we want to add 7 to the list so that the user has a choice select 7 too. So, where should it be displayed? Ans: It will be displayed in all the lists because 1+2+4 = 7. So, if the user says his number is in all the three lists, we just add the numbers (the numbers in the beginning of the list) and get 7.

      What we are doing in my program is we are using only the numbers 1, 2, 4, 8, 16, 32 and 64 to make up the number the user has selected. So, let’s say in my program one has selected the number 28. So, it will be present in the lists starting with the numbers 16, 8 and 4. Because these are the only three numbers (out of 1,2,4,8,16,32and64) which can make 28 without repetition.

      The variable “b” (in my program) adds the number shown at the beginning of the lists in which the user’s number is present.

      EXTRA EXAMPLE: If user’s number is 64, it will be present only in the list starting with the number 64. However, if the user’s number is 63, it will be present in all the other lists except 64 because (1+2+4+8+16+32=63). So, the “b” variable will add all the numbers in the beginning of all the lists except 64 and arrive at 63 in the end.

      Extra TIP: In my program, you can even add numbers after 100 (you can add up to 1+2+4+8+16+32+64 i.e. 127). :D For example, 127 will appear in all the lists. 126 will appear in all the lists except for the one which starts with 1. I have not given the choice to select numbers beyond 99 because it appears more systematic and normal.

      Pardon my bad explanation in this comment, but this is only because it is difficult to explain without spending a lot of time. I do hope that you are able to understand the LOGIC of this magic trick now.

      Thank you.

      Reply
      1. Sumit

        Brother, I am not able to understand that. can you please explain it in An easy Way?
        I want to Understand This Please …

        Reply

Leave a Reply

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