Post 3 - Build a Magician's Number Finder System using Java

 Welcome to the blog !!  There is no shortcut to the success. Small daily improvements over time lead to great success. So let's improve knowledge of Java language to become master in java programming.

I will recommend you to go through my previous posts - Build Simple Calculator  and  Build Email Generator  

Today , we will learn to build Magician's Number Finder System using some concepts of Java.

✅ Problem Statement:

The king of Devpur village wants to find Magician's Number from given collection of numbers but he is not expert in mathematics so he require a system which will automatically find Magicians Number from given numbers.
King told that Number is called Magician's Number only if it is Multiple of 7.

✅ Concepts of Java covered in this Project :

  1. Take Input and Display Output
  2. Arrays 
  3. Call Method from Another Method in Same Class

📑 Let's Code :) 

Let's build Magician's Number finder System 😊

Step 1: Open Eclipse and Right Click on src under your project. 
If you don't have created project , Click on File → New → Java Project and create your project and then right click on src . Then follow the process shown in fig :


When you click on class , it will open new window for creating class.

Step 2: For this project we need to create a class. 
  

Once you do all the changes mentioned above, click on Finish. This will create a new magicianNum class having main () method.

Before we start actual coding , let's go through concept of Array in Java

🔴 Concept to Learn :

Que - What is Array ?
⇒ Array is the sequential collection of elements of same data type. We need to pre-allocate space to array before storing the elements. So array is called Fixed Size data structure. If we add element more than available space, it throws ArrayIndexOutOfBound exception. 
  
 
Que- How to Declare and Allocate Size to array  ?
  Array can be declare in 2 ways :


Array is the static data structure and require to allocate memory space before storing elements in it.
We can declare array and then allocate memory to it as follows - 


Or we can merge array declaration and memory allocation in single line 


Step 3:  Let's complete magicianNum class .

This class will contain -

  1. Take input from user.
  2. Initialize array and allocate size
  3. Store elements in array
  4. Call one method from another method within same class
  5. Find Magician's Number from array element 
  6. Print output to the console
Here is the sample code for magicianNum class :

magicianNum 1.1

magicianNum 1.2

Step 4: Save your code and Run the project by pressing Ctrl+F11.

 I'm attaching screenshots taken by running the project twice and giving 2 different outputs.

Sample Output : 
 
Output 1


Output 2

We are done with our another project !!

You can check source code Here


All the Best 👍👍👍

Happy Learning 😀😀❗❗


Post a Comment

Comments :

Previous Post Next Post