CODE
class PrintVariableValue
{
public static void main(String arg[])
{
int numberOfStudents = 34; // LINE A
int highestMarks = 98;
System.out.println("The class has " + numberOfStudents + " students and the highest marks are " + highestMarks + ".");
}
}
The class has 34 students and the highest marks are 98.
Here we declared variables numberOfStudents
and highestMarks
. Both of them are of type int
. We have concatenated varialables and strings to print the formatted output.
numberOfStudents
to 56
and highestMarks
to 25
and observe the output.averageMarks
and set it to 53.2
. Print the average marks in the format "Average marks are 53.2".LINE A
, change the variable name from numberOfStudents
to numberofstudents
(change O and S from capitals to small letters) but do not change it in the print statement. Observe the compilation error you get. Note that the variable names are case-sensitive.3idiots
, v@r##
and number of students
and see what compilation errors you get.