Pass the Test, Win the Heart

Pass the Test, Win the Heart

Hi everyone!

Today, I want to share a small creative story that connects marriage with programming logic. I hope you enjoy it.

The Wedding Gate and the Tests

Once upon a time, there was a girl named Sravani. She was ready to get married but she didn’t believe in just looks, money, or status. She believed in logic.

So, a special gate was set up to find the right person. This gate was controlled by Shyam, an old soul who loved checking values through simple rules.

To pass the gate, the groom's name had to pass four tests based on the length of the name. Each one revealed something deeper about the person.

1.Mirror Test(Palindrome):

  • First, the number (length of the name) should look the same from both sides like a mirror.
  • If yes it showed honesty and a clean heart.

2.Prime Test:

  • Next, the number had to be a prime number.
  • If yes it meant the person was special and strong-minded, standing on their own.

3.Parent's Background(Square Test):

  • Now, the square of that number had to be between 10 and 99.
  • This showed a stable family with good values and balance.

Four Father's Legacy(Cube Hint):

  • Finally, this square should fall between 100 and 999.
  • This hinted that the person’s family legacy was strong and well known.

The Result:

  • Sravani whispered the name. The tests began and one by one, everything passed.
  • At last, the gate opened with a smile and said.

Selected:

  • Because this match wasn’t just about outer things.
  • It was a perfect blend of logic, values, and background.

Features of the Story:

1. Creative mix of logic and real life (marriage + programming).

2. Uses 4 fun tests – Palindrome, Prime, Square, Cube.

3. Easy way to learn math and logic through a story.

4. Positive message – values and logic matter in life choices.

5. Short and meaningful – perfect for students or beginners.

Logic Flow:


Article content

Topics used in this Code:

1. String Length

  • Used to get the number of characters in the groom's name.

2. Palindrome Check

  • To check if the number (length) reads the same backward.

3. Prime Number Check

  • Logic to test if a number has only 2 factors (1 and itself).

4. Square Calculation

  • Finding the square of the number and checking if it's between 10 and 99.

5. Range Checking

  • Used to verify if square is between 100 and 999 (in the last test).

6. Conditional Statements

  • To apply logic like if, else if, else for passing each test.

7. Function Use (Optional)

Can use separate functions for each test for modular code.

Java Code:

import java.util.Scanner;

class Test {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

// Step 1: Input

System.out.print("Enter a string: ");

String str = sc.nextLine();

// Step 2: Length

int len = str.length();

// Step 3: Check if length is palindrome

if (!isPalindrome(len)) {

System.out.println("Not Selected");

return;

}

// Step 4: Check if length is prime

if (!isPrime(len)) {

System.out.println("Not Selected");

return;

}

// Step 5: Square

int square = len * len;

if (square < 10 || square > 99) {

System.out.println("Not Selected");

return;

}

// Step 6: Cube

int cube = len len len;

if (square >= 100 || square <= 999) {

System.out.println("Selected");

} else {

System.out.println("Not Selected");

}

}

// Function to check palindrome number

static boolean isPalindrome(int n) {

int temp = n, rev = 0;

while (n > 0) {

int rem = n % 10;

rev = rev * 10 + rem;

n /= 10;

}

return temp == rev;

}

// Function to check prime number

static boolean isPrime(int n) {

if (n <= 1) return false;

for (int i = 2; i <= n / 2; i++) {

if (n % i == 0)

return false;

}

return true;

}

}

Output:



Article content
Article content

Conclusion:

This program checks if the length of a given string meets certain conditions like being a palindrome, prime number, and having a valid square and cube range. It helped me apply basic Java concepts like input, loops, conditions, and functions in a clear and logical way.

Just wrapped up our Project!

A special thanks to our HOD Dr. P. Vijaya Bharati Mam and Dean of Placements Dr. Manendra Sai Dasari Sir for their constant encouragement and for providing us the opportunities to excel. I also like to extend my gratitude to my mentor Dinesh Kumar Thangavel Sir for his amazing mentorship, guidance and support throughout this project. My Amazing team Pasta Jagilinki Harika SAMEERA APPIKONDA Keerthi Mamidipaka grateful for my entire team for the Collaboration, for the efforts that you have contributed and for the teamwork!

#JavaProgramming #CodingLogic #PalindromeCheck #PrimeNumber #JavaBasics #LearnToCode #ProgrammersLife #TechLearning

To view or add a comment, sign in

Others also viewed

Explore content categories