In our examples, variable names are often simplified to reflect their data type (e.g., using “myInt” or “myNum” for integer types and “myChar” for character types) to prevent confusion.
For a practical illustration of variable usage, consider the following program that manages various data for a college student.
// Student data String studentName = “John Doe”; int studentID = 15; int studentAge = 23; float studentFee = 75.25f; char studentGrade = ‘B’; // Print variables System.out.println(“Student name: “ + studentName); System.out.println(“Student id: “ + studentID); System.out.println(“Student age: “ + studentAge); System.out.println(“Student fee: “ + studentFee); System.out.println(“Student grade: “ + studentGrade);
|
In this practical example, we develop a program to compute the area of a rectangle by multiplying its length and width:
// Create integer variablesint
|