0% found this document useful (0 votes)
3 views6 pages

Program 4

The document contains a Java program demonstrating basic programming concepts, including different kinds of literals, operators, and variables. It provides examples of integer, float, double, char, string, and boolean literals, as well as arithmetic, relational, logical, assignment, unary, and ternary operators. Additionally, it explains static, instance, and local variables with corresponding outputs.

Uploaded by

paxojak623
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

Program 4

The document contains a Java program demonstrating basic programming concepts, including different kinds of literals, operators, and variables. It provides examples of integer, float, double, char, string, and boolean literals, as well as arithmetic, relational, logical, assignment, unary, and ternary operators. Additionally, it explains static, instance, and local variables with corresponding outputs.

Uploaded by

paxojak623
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PROGRAM:4

Create a basic Java program for demonstrating the use of basic concepts like:

A. Different kinds of literals

B. Different kinds of operators

C. Different kinds of variables

(a) Different kinds of literals

package shreyansh123;

public class literals {

public static void main(String[] args) {


[Link]("--Different kinds of literals--");

int intLiteral=100;
float floatLiteral=12.5f;
double doubleLiteral=99.99;
char charLiteral='R';
String stringLiteral="Java";
boolean booleanLiteral=true;

int binaryLiteral=0b1010;
int octalLiteral=012;
int hexLiteral=0x1F;

[Link]("Integer Literals:" + intLiteral);


[Link]("Float Literals:" + floatLiteral);
[Link]("double Literals:" + doubleLiteral);
[Link]("char Literals:" + charLiteral);
[Link]("string Literals:" + stringLiteral);
[Link]("boolean Literals:" + booleanLiteral);

[Link]("Binary Literals(0b1010):" + binaryLiteral);


[Link]("octal Literals(012):" + octalLiteral);
[Link]("Hex Literals(0x1F):" + hexLiteral);

}
}

OUTPUT
(b) Different kinds of operators

package shreyansh123;

public class operatorsDemo {

public static void main(String[] args) {

int a=20;
int b=10;
[Link]("--Different kinds of operators--");

//Arithmetic Operators
[Link]("\nArithmetic Operators:");
[Link]("a+b=:" +(a+b));
[Link]("a-b=" +(a-b));
[Link]("a*b=" + (a*b));
[Link]("a/b=" +(a/b));
[Link]("a%b=" +(a%b));

// Relational Operators
[Link]("\nRelational Operators:");
[Link]("a > b : " + (a > b));
[Link]("a < b : " + (a < b));
[Link]("a == b : " + (a == b));
[Link]("a != b : " + (a != b));

// Logical Operators
[Link]("\nLogical Operators:");
boolean x = true, y = false;
[Link]("x && y : " + (x && y));
[Link]("x || y : " + (x || y));
[Link]("!x : " + (!x));

// Assignment Operators
[Link]("\nAssignment Operators:");
int c = 5;
c += 2;
[Link]("c += 2 : " + c);
c -= 1;
[Link]("c -= 1 : " + c);

// Unary Operators
[Link]("\nUnary Operators:");
int d = 10;
[Link]("d++ = " + (d++));
[Link]("After d++ : " + d);
[Link]("++d = " + (++d));

// Ternary Operator
[Link]("\nTernary Operator:");
int max = (a > b) ? a : b;
[Link]("Max = " + max);
}

}
[Link] types of variables.

package [Link];

public class program {

// Static Variable
static int staticVar = 250;

// Instance Variable
int instanceVar = 70;

public static void main(String[] args) {

// Local Variable
int localVar = 35;

[Link]("---- Different Types of Variables ----");

// Static variable access


[Link]("Static Variable: " + staticVar);

// Instance variable access


program obj = new program();
[Link]("Instance Variable: " + [Link]);

// Local variable access


[Link]("Local Variable: " + localVar);
}
OUTPUT

You might also like