This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) { | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) { | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
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 | |
} | |
} | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Import libraries required by the following code | |
*/ | |
/** | |
* SOLUTION | |
*/ | |
import java.util.List; | |
import java.util.ArrayList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Create a new Dog instance ... | |
* Make the dog size = 10 | |
*/ | |
class App { | |
public static void main(String[] args) { | |
/** | |
* SOLUTION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 | |
} | |
} |
NewerOlder