Menu
Topics Index
...
`

Session 19 has these questions


Average of Three Numbers

Write a program to get the average of three numbers;
class ThreeNumbersAverage

{    public static void main(String s[])
    {
        System.out.println("Average of 15, 70 and 27 is " + average(15, 70, 27));

    }


public static int average(int a, int b, int c)
{
int result = 0;
//Write code here to get the average of a, b and c and assign it to result
return result;
}
}



Calculate sum of doubles

What will be the output of the following program?
class SumOfDoubles
{
    public static void main(String args[])
    {
    
        double d1 = 0.7;
        double d2 = 77.0/1000.0;
        double d3 = d1 * 10;
        double d4 = 77E+2;
        double d5 = 77E-5;

        double sum = d1 + d2 + d3 + d4 + d5;
        
        System.out.println("sum = " + sum);
    }
}
A. sum = 7707.77777
B. sum = 7777.77777
C. Compilation errors.
D. sum = 7770.77077



Evaluate Equation

Write a program to get the value of y for a given x where
y = 4x^2 - 22x + 129; // x^2 is x square
class Function1

{    public static void main(String s[])
    {
        System.out.println("When x = 5, y is " + calculateY(5) );

    }


public static int calculateY(int x)
{
int y = 0;
//Write code here to calculate the value of y for the given x.
return y;
}
}



Multiply two numbers

Write a program to multiply two numbers.
class MultiplyNumbers

{    public static void main(String s[])
    {
        System.out.println("Multiplication of 5 and 7 is " + multiply(5,7));

    }


public static int multiply(int a, int b)
{
int result = 0;
//Write code here to multiply a and b and assign it to result
return result;
}
}



Add Two Numbers

Write a program to add two numbers.
class AddNumbers

{    public static void main(String s[])
    {
        System.out.println("Sum of 21 and 18 is " + sum(21, 18));

    }


public static int sum(int a, int b)
{
int result = 0;
//Write code here sum a and b and assign it to result
return result;
}
}



© meritcampus 2019

All Rights Reserved.

Open In App