Menu
Topics Index
...
`

Weekend Hack - 05 Jan 2013 - Rs. 150 has these questions


Find the Love Index of a couple

Write a program to get the love index of couple. The index is calculated by cancelling out the common letters in the names, then summing up the remaining letters for each name and then dividing the small character sum with the bigger character sum. And finally multiplying the result with hundred. Note that both small and capital letters will have the same weightage, so 'M' and 'm' have a score of 13.
Input (Char Array, Char Array) Output (Double)
{L, a, i, l, a}, {M, a, j, n, u} L + i + l + a = 12 + 9 + 12 + 1 = 34
M + j + n + u = 13 + 10 + 14 + 21 = 58
Index = ( 34 / 58 ) * 100 = 58.62069
{R, o, m, e, o}, {J, u, l, i, e, t} R + o + m + o = 18 + 15 + 13 + 15 = 61
J + u + l + i + t = 10 + 21 + 12 + 9 + 20 = 72
Index = ( 61 / 72 ) * 100 = 84.72222
{N, a, g, a, r, j, u, n, a}, {A, m, a, l, a} N + g + r + j + u + n = 14 + 7 + 18 + 10 + 21 + 14 = 84
m + l = 13 + 12 = 25
Index = ( 25 / 84 ) * 100 = 29.7619
class FindLoveIndex

{    public static void main(String s[])
    {
        char person1[] = {'R', 'o', 'm', 'e', 'o'};
        char person2[] = {'J', 'u', 'l', 'i', 'e', 't'};
        System.out.println("The love index of Romeo and Juliet  : " + getLoveIndex(person1, person2));

    }


public static double getLoveIndex(char person1[], char person2[]) {
//Write a code here to calculate the love index of the persons and return it.
}
}




Print numbers in reverse order using while

What will be the output of the following program?
class WhileExample
{
    public static void main(String s[])
    {
        int n = 5;

        while( n > 0 )
        {
            n--;
            System.out.println("n = " + n );
        }
    }
}
A. n = 4
n = 3
n = 2
n = 1
B. n = 4
n = 3
n = 2
n = 1
n = 0
C. n = 5
n = 4
n = 3
n = 2
n = 1
n = 0
D. n = 5
n = 5
n = 5
n = 5
n = 5



© meritcampus 2019

All Rights Reserved.

Open In App