0% found this document useful (0 votes)
10 views4 pages

Java 1-3

The document contains two Java programs demonstrating the evaluation of expressions and operators, as well as conditional and control statements. The first program performs arithmetic, logical, relational, and bitwise operations, displaying the results for each. The second program uses conditional statements to determine and print the greatest of three integers.

Uploaded by

mushfiqshaikh2
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)
10 views4 pages

Java 1-3

The document contains two Java programs demonstrating the evaluation of expressions and operators, as well as conditional and control statements. The first program performs arithmetic, logical, relational, and bitwise operations, displaying the results for each. The second program uses conditional statements to determine and print the greatest of three integers.

Uploaded by

mushfiqshaikh2
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
You are on page 1/ 4

Practical 2

Q) Write programs to evaluate different types of expressions and operators

Code:-

public class HelloWorld {

public static void main(String[] args) {

System.out.println("Name: Shaikh Mushfiq");

System.out.println("Rollno: 230449");

double num1 = 10;

double num2 = 5;

// Perform operations

double addition = num1 + num2;

double subtraction = num1 - num2;

double multiplication = num1 * num2;

double division = num1 / num2;

// Display results

System.out.println("Addition: " + addition);

System.out.println("Subtraction: " + subtraction);

System.out.println("Multiplication: " + multiplication);

System.out.println("Division: " + division);

boolean a = true;

boolean b = false;

// Perform logical operations

boolean andResult = a && b;

boolean orResult = a || b;

// Display results

System.out.println("AND (true && false): " + andResult);


System.out.println("OR (true || false): " + orResult);

System.out.println("NOT (!true): " + (!a));

int x = 10;

int y = 5;

// Perform relational operations

boolean greater = x > y;

boolean less = x < y;

boolean equal = x == y;

boolean notEqual = x != y;

// Display results

System.out.println("x > y: " + greater);

System.out.println("x < y: " + less);

System.out.println("x == y: " + equal);

System.out.println("x != y: " + notEqual);

int bita = 6; // Binary: 110

int bitb = 3; // Binary: 011

int result_2 = bita & bitb; // Bitwise AND

int result_1 = bita | bitb; // Bitwise OR

int xorResult = bita ^ bitb; // Bitwise XOR

System.out.println("a & b (AND): " + result_2); // 2 (Binary: 010)

System.out.println("a | b (OR): " + result_1); // 7 (Binary: 111)

System.out.println("a ^ b (XOR): " + xorResult); // 5 (Binary: 101)

int bitc = 6; // Binary: 0000 0110

int notResult = ~bitc; // Bitwise NOT


System.out.println("~a (NOT): " + notResult); // -7 (Two's complement)

Practical 3

Q) Write programs to demonstrate Conditional and Control Statements

Code:-

public class HelloWorld {

public static void main(String[] args) {

int a =10;

int b= 30;

int c= 25;

System.out.println("Name:- Shaikh Mushfiq");

System.out.println("Rollno:- 230449");

if (a>b && a>c) {

System.out.println("A is the greatest");


} else if (c>b) {

System.out.println("C is the greatest");

} else if (b>a) {

System.out.println("B is the greatest");

You might also like