Menu
Topics Index
...
`

Intermediate Level Test 10 has these questions


Find Nearest Fibonacci Number

Write a program to find the nearest Fibonacci number. The Fibonacci numbers are 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 etc.,. Assume that the input number will be always greater than 3. There is no upper limit to the input number.
Input (Integer) Output (Integer)
9 8 (9 is between 8 and 13 and is nearer to 8 than 13)
29 34 (29 is between 21 and 34 and is nearer to 29 than 34)
50 55 (50 is between 34 and 55 and is nearer to 55 than 34)
class FindNearestFibonacciNumber

{    public static void main(String s[])
    {
        int input = 245;
        int result = findNearestFibonacciNumber(input);
        
        System.out.println("The nearest Fibonacci number for " + input + " is " + result);

    }


public static int findNearestFibonacciNumber(int input)
{
//Write code here to find the nearest Fibonacci number to the given input and return the same.
}
}



Find Student With Highest Marks

Write a program to find the Student with highest marks out of the 3 students passed as parameters.
class FindStudentWithHighestMarks

{    public static void main(String s[])
    {
        Student munnu = new Student("Munnu", 72);
        Student satish = new Student("Satish", 88);
        Student sreekanth = new Student("Sreekanth", 89);
        
        Student topper = getStudentWithHighestMarks(munnu, satish, sreekanth);
        
        System.out.println("The topper is " + topper.name);

    }


public static Student getStudentWithHighestMarks(Student s1, Student s2, Student s3)
{
//Write code here to find student with highest marks and return the same
}
}
class Student
{
String name;
int marks;

Student(String name, int marks)
{
this.name = name;
this.marks = marks;
}
}



Define Water Bottle Class

Define a class WaterBottle with the attributes capacity, material, color, hasCap. There data types are double, String, String and boolean respectively.
class DefineWaterBottleClass

{    public static void main(String s[])
    {
        WaterBottle waterBottle = new WaterBottle();
        waterBottle.capacity = 1.25;
        waterBottle.material = "Plastic";
        waterBottle.color = "Pink";
        waterBottle.hasCap = true;
        System.out.println( waterBottle.color + " water bottle made of " + waterBottle.material + " has a capacity of " + waterBottle.capacity + " liters.");

    }


}
//Write code here to define the class WaterBottle as per the specifications.



Classify Integer

Write a program to print the classification for every integer in the given range. E for even, O for odd, OX for odd and divisible by 3, OXY for odd and divisible by 9, OXYZ for odd and divisible by 27. When printing the integer should be prefixed and suffixed with tilda(~).
RULES: Do not use nested if's or Boolean logical AND(&) operator in the program.
Input (Integer Range) Output Printed
20 to 28 ~20~E~21~OX~22~E~23~O~24~E~25~O~26~E~27~OXYZ~28~E
1 to 10 ~1~O~2~E~3~OX~4~E~5~O~6~E~7~O~8~E~9~OXY~10~E
80 to 85 ~80~E~81~OXYZ~82~E~83~O~84~E~85~O
class ClassifyIntegers

{    public static void main(String s[])
    {
        classifyIntegers(20, 40);

    }


public static void classifyIntegers(int start, int end)
{
//Write code here to classify the integers as mentioned in the question.
}
}



Find Number Properties

Write a program to return the properties - isPerfectSquare, isPrimeNumber, previousNumber, nextNumber, square and cube - for the given input number.
Input (Integer) Output (NumberProperites)
25 isPerfectSquare = true
isPrimeNumber = false
previousNumber = 25 - 1 = 24
nextNumber = 25 + 1 = 26
square = 25 * 25 = 625
cube = 25 * 25 * 25 = 15625
7 isPerfectSquare = false
isPrimeNumber = true
previousNumber = 7 - 1 = 6
nextNumber = 7 + 1 = 8
square = 7 * 7 = 49
cube = 7 * 7 * 7 = 343
10 isPerfectSquare = false
isPrimeNumber = false
previousNumber = 10 - 1 = 6
nextNumber = 10 + 1 = 8
square = 10 * 10 = 100
cube = 10 * 10 * 10 = 1000
class FindNumberProperties

{    public static void main(String s[])
    {
        NumberProperties properties = getProperties(7);
        
        System.out.println("Printing the properties of the number 7");
        System.out.println("---------------------------------------");
        System.out.println("Perfect Square : " + properties.isPerfectSquare);
        System.out.println("Prime Number : " + properties.isPrimeNumber);
        System.out.println("Previous Number : " + properties.previousNumber);
        System.out.println("Next Number : " + properties.nextNumber);
        System.out.println("Square : " + properties.square);
        System.out.println("Cube : " + properties.cube);

    }


public static NumberProperties getProperties(int input)
{
//Write code here to create a NumberProperties object. Get the required properties of the input number and assign them to the NumberProperties object. Also return the created object.
}
}
class NumberProperties
{
boolean isPerfectSquare;
boolean isPrimeNumber;
int previousNumber;
int nextNumber;
int square;
int cube;
}



© meritcampus 2019

All Rights Reserved.

Open In App