Menu
Topics Index
...
`

Intermediate Level Test 2 has these questions


Arithmetic Operators Incorrect statement

Choose the incorrect statement about the following expressions?
a=a+1;        // Expression 1
a++;        // Expression 2
a+=1;        // Expression 3
++a;        // Expression 4
A. All expressions give the same result
B. 'Expression 2' is faster that 'Expression 3' which inturn is faster than 'Expression 1'
C. The value of 'a' after 'Expression 2' is different from 'Expression 4'
D. The value of 'a' after 'Expression 1' is same as 'Expression 3'



Feet To Centi Meters Conversion

Write code to convert a given number from feets (ft) to centi meters (cm).
Note that '1 foot = 0.3048 meters' and '1 meter = 100 centi meters'
class FeetToCMConversion

{    public static void main(String s[])
    {
        System.out.println(" 25 feet is same as " + convertToCentiMeter(25) + " cm");

    }


public static double convertToCentiMeter(double feet)
{
double result = 0;
//Write code here to convert feet into centi meters and assign it to result
return result;
}
}



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;
}
}



Convert Temperatures

Write a program to convert between celsius and fahrenheit.
Note that 'C = 5(F - 32)/9'
class CelsiusToFahrenHeit

{    public static void main(String s[])
    {
        System.out.println("98.4 degrees fahrenheit is same as " + fahrenheitToCelsius(98.4) + " celsius");
        System.out.println("100 degrees celsius is same as " + celsiusToFahrenheit(100) + " fahrenheit");
        System.out.println("-40 degrees celsius is same as " + celsiusToFahrenheit(-40) + " fahrenheit");

    }


public static double fahrenheitToCelsius(double fahrenheit)
{
double celsius = 0;
//Write code here to convert fahrenheit and assign it to celsius.
return celsius;
}

public static double celsiusToFahrenheit(double celsius)
{
double fahrenheit = 0;
//Write code here to convert celsius and assign it to fahrenheit.
return fahrenheit;
}
}



Arrange by operator precedence

Arrange the following in the order of precedence, with highest precedence on the top.
  • move + (addition)
  • move ++ (increment)
  • move / (division)
  • move () (parenthesis)
  • move * (multiplication)
  • move - (minus)



© meritcampus 2019

All Rights Reserved.

Open In App