From 6fbcc4ac72542b4e403ea1edcc05e5cef823d071 Mon Sep 17 00:00:00 2001 From: uvhareesh Date: Tue, 13 May 2025 19:24:40 +0530 Subject: [PATCH] Variables concept added in Data types.java file --- src/coreJava/DataTypes.java | 49 +++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/src/coreJava/DataTypes.java b/src/coreJava/DataTypes.java index 7b09fc9..6f0e47c 100644 --- a/src/coreJava/DataTypes.java +++ b/src/coreJava/DataTypes.java @@ -3,11 +3,54 @@ public class DataTypes { public static void main(String[] args) { + + //variables + + //int s; //declaration + //s=100; //assignment + + int s=100; // declaration+assignment + System.out.println(s); + + s=200; + System.out.println(s); + + /* + // approach1 // if all the variables belongs to different data types + int p=1; + int o=2; + int i=3; + */ + + /* approach2 // only if allthe variable are belongs to same data type + int p,o,i; + p=1; + o=2; + i=3; + */ + + // approach3 //only if all the variable are belongs to same data type + int p=1,o=2,i=3; + + //for meaningful message in print statement we can use concatenation method + System.out.println("The Value of p is :"+p); + System.out.println("The Value of o is :"+o); + System.out.println("The Value of i is :"+i); + + // in single line we printed all variable values + System.out.println(p+""+o+""+i+""); + + // in print statement we used join method for each value with "" + + +//-------------------------------------------------------------------------- + // Data types + // Numeric Data Types int a=100, b=200; - System.out.println("The vlaue of a is :"+a); - System.out.println("The vlaue of b is :"+b); + System.out.println("The Value of a is :"+a); + System.out.println("The Value of b is :"+b); System.out.println(a+b); System.out.println("The sum of an and b is : "+(a+b)); @@ -56,6 +99,8 @@ public static void main(String[] args) { //String bl=true;//invalid String bl2="true";//valid + //---------------------------------------------------------------------- + //difference between variable and const/final int x=100; System.out.println(x);