Skip to content

Instantly share code, notes, and snippets.

/**
* Declare Number no as float 22.23 ...
* Use object's shortValue() method and ...
* Display no as 22
*/
class App {
public static void main(String[] args) {
/**
/**
* Create an array nums of integers ...
* The array must have the length = 3 ...
* First element nums[0] should display 100
*/
class App {
public static void main(String[] args) {
/**
/**
* Define abstact class Animal
* Class Animal contains two methods, eat() and showName()
* One of the method is abstract
*/
class App {
public static void main(String[] args) {
Dog d = new Dog();
d.setName("MyDog");
System.out.println(d.name); // MyDog
/**
Define MyMath.floor() method using java.lang.math method
class App {
public static void main(String[] args) {
double n = MyMath.floor(12.3);
System.out.print(n); // 12.0
}
}
*/
/**
* Define a string s1 = "1"
* Define a number n1 = 2
* Display the sum of s1 + n1 = 3
* (convert the string to number)
*/
class App {
public static void main(String[] args) {
/**
* Import libraries required by the following code
*/
/**
* SOLUTION
*/
import java.util.List;
import java.util.ArrayList;
/**
* Create a new Dog instance ...
* Make the dog size = 10
*/
class App {
public static void main(String[] args) {
/**
* SOLUTION
/**
* Write constructor and method for Output class.
* The output() prints the <name> instance variable
*/
class App {
public static void main(String[] args) {
Output o = new Output("John");
o.output(); // John
}
}
/**
* Declare showInfo() method ...
* The method should display "Cooper is 3 age old" ...
* The method must have no return type
*/
class App {
public static void main(String[] args) {
/**
* Define Dog class which
* Dog class must implement the correct class
*/
class App {
public static void main(String[] args) {
Dog d = new Dog();
d.bark(); // The dog is barking
}
}