...

/

Solution Review: Variable Declaration

Solution Review: Variable Declaration

The solution to the variable declaration exercise is explained in this lesson.

We'll cover the following...

Solution review

Let’s take a look at the code first:

Press + to interact
public class PrimitiveDataTypes {
public static void main(String args[]) {
byte age = 10;
// byte distance = 144; // exceeding range
short height = 30000; // inside range
// short elevation = 40000; // outside range
int distanceBetweenTwoSatellites = 1000000000; // inside range
// int distanceBetweenTwoGalaxy = 10000000000; // outside range
long distanceBetweenTwoGalaxy = 10000000000L; // inside range
float rateOfInterest = 6/5f; // range is beyond the scope of discussion
double rateOfHike = 456/123d; // range is beyond the scope of discussion
char capitalA = 'A';
boolean isPossible = true;
System.out.println("Age is: " + age);
System.out.println("Height is: " + height);
System.out.println("Distance between two satellites is: " + distanceBetweenTwoSatellites);
System.out.println("Distance between two galaxies is: " + distanceBetweenTwoGalaxy);
System.out.println("Rate of interest is: " + rateOfInterest);
System.out.println("Rate of hike is: " + rateOfHike);
System.out.println("CapitalA: " + capitalA);
System.out.println("isPossible: " + isPossible);
}
}

Explanation

The solution is pretty straight forward. The highlighted lines (5, 7, ...