Java Variable Declarations Made Easy: A Step-by-Step Tutorial

             


               Simple program that demonstrates the fundamental concept of variable declarations and assignments. It consists of a `main` method, which is the entry point for Java programs, and within this method, three different variables of distinct data types are declared, assigned values, and then printed to the console.

                Firstly, an integer variable `num` is declared and assigned the value 45. This illustrates the declaration and initialization of an integer variable in Java. Subsequently, the value of `num` is printed to the console, resulting in the output of "45."

                Next, a double precision floating-point variable `val` is declared and initialized with the value 7.89. This demonstrates how to work with floating-point numbers in Java. The value of `val` is then printed, producing "7.89" as the output.

                Lastly, a character variable `ch` is declared and assigned the character 'J'. This showcases the declaration of a character variable in Java, and the character 'J' is printed to the console as the output.

Program:
  class Program1
{
public static void main(String[] args)
{
int num;
num=45;
System.out.println(num);//45
double val;
val=7.89;
System.out.println(val);//7.89
char ch;
ch='J';
System.out.println(ch);//J
}
}

0 Comments

Post a Comment

Post a Comment (0)

Previous Post Next Post