Skip to main content

In this blogging you know about digital world.

Function in C

  Function Function : In C programming, a function is a self-contained block of code that performs a specific task or a set of related tasks. Functions are used to break down a program into smaller, more manageable pieces, making the code more organized, readable, and reusable. C supports various types of functions, including library functions and user-defined functions. Below, I'll describe functions in C with examples and discuss their types. Function Syntax: return_type function_name(parameters) {     // Function body     // Statements to perform a task     return value; // (optional) Return value } Here's a breakdown of the elements: - `return_type`: Specifies the data type of the value the function returns. Use `void` if the function doesn't return anything. - `function_name`: A unique identifier for the function. - `parameters`: Input values that the function can accept (optional). - `function_body`: Conta...

Write a Programe in Java for Love Calculator.


Write a Programe in Java for Love Calculator. 

Save this file LoveCalculator.java

Copy Paste and Enjoy


import java.util.Scanner;


public class LoveCalculator {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        

        System.out.println("Welcome to the Love Calculator!");

        System.out.print("Enter the first name: ");

        String name1 = scanner.nextLine().toLowerCase(); // Convert to lowercase for case insensitivity

        System.out.print("Enter the second name: ");

        String name2 = scanner.nextLine().toLowerCase(); // Convert to lowercase for case insensitivity


        int totalScore = calculateLoveScore(name1, name2);

        

        System.out.println("Love Score: " + totalScore + "%");

        System.out.println(interpretLoveScore(totalScore));

        

        scanner.close();

    }

    

    // Calculate the love score

    public static int calculateLoveScore(String name1, String name2) {

        String combinedNames = name1 + name2;

        int loveScore = 0;

        

        for (int i = 0; i < combinedNames.length(); i++) {

            char currentChar = combinedNames.charAt(i);

            loveScore += currentChar;

        }

        

        return loveScore % 101; // Keep the score within 0-100

    }

    

    // Interpret the love score

    public static String interpretLoveScore(int loveScore) {

        if (loveScore >= 80) {

            return "You are a perfect match!";

        } else if (loveScore >= 60) {

            return "You have a good chance together!";

        } else if (loveScore >= 40) {

            return "There's potential, but work on it!";

        } else {

            return "Not a great match, but who knows!";

        }

    }

}


Comments

Popular Posts