Page 82 - CA_Blue( J )_Class10
P. 82
When you execute the preceding program, the current data of the computer will be returned, as shown:
Today is: Mon Sep 23 14:15:21 IST 2024
5.1.2 Advantages of Packages
Advantages of using packages are:
• Packages allow us to create multiple classes with the same name in different packages.
• Packages increase the reusability of code as a class in one package can be used in another package.
• Packages make the management of classes easy.
5.2 INITIALIZATION
Initialization refers to assigning an initial value to a variable before using the variable in the program. This method of
input is also known as direct input or hard-coded input.
You can initialize a variable in two ways:
i. By assigning the value at the time of declaration. For example,
int a = 5, b = 6;
ii. By assigning the value after the declaration. For example,
int a, b;
a = 5;
b = 4;
Let us take a look at an example.
Program 2 To print the area and circumference of a circle whose radius is 5.6 cm.
1 class initialize_value
2 {
3 public static void main()
4 {
5 float radius,area,circumference;
6 radius=5.6f;
7 area=(float)(22.0/7.0*radius*radius);
8 circumference=(float)(2*22.0/7.0*radius);
9 System.out.println("Area of circle : "+area);
10 System.out.println("Circumference of circle : "+circumference);
11 }}
You will get the following output:
Explanation: Since the radius is float type, it is initialized with 5.6f. The expression 22.0/7.0 results in double, so it is
explicitly converted into float.
8080 Touchpad Computer Applications-X

