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.
}
}
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;
}
}
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.
~
).
&
) 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.
}
}
isPerfectSquare
, isPrimeNumber
, previousNumber
, nextNumber
, square
and cube
- for the given input number.
Input (Integer) | Output (NumberProperites) |
---|---|
25 |
|
7 |
|
10 |
|
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;
}