0% found this document useful (0 votes)
22 views2 pages

Java Exp 1

The document contains two Java experiments. The first experiment (Exp1) generates a pattern of stars in a pyramid shape, while the second experiment (Exp1B) performs various operations on two integers and displays the results. Both experiments demonstrate basic programming concepts such as loops and bitwise operations.

Uploaded by

arunmali3302
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)
22 views2 pages

Java Exp 1

The document contains two Java experiments. The first experiment (Exp1) generates a pattern of stars in a pyramid shape, while the second experiment (Exp1B) performs various operations on two integers and displays the results. Both experiments demonstrate basic programming concepts such as loops and bitwise operations.

Uploaded by

arunmali3302
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

Experiment No:1

package Experiments;

public class Exp1 {

public static void main(String[] args) {

int rows = 4; // Number of rows in the pattern

for (int i = 0; i < rows; i++) {

// Print leading spaces

for (int j = 0; j < i; j++) {

[Link](" ");

// Print stars

for (int j = 0; j < (rows - i); j++) {

[Link]("* ");

// Move to the next line

[Link]();

Output:
Experiment 1(B)

package Experiments;

public class Exp1B {

public static void main(String[] args) {

// Initialize variables

int a = 10, b = 5;

// i) (a << 2) + (b >> 2)

int result1 = (a << 2) + (b >> 2);

// ii) (a) || (b > 0)

boolean result2 = (a != 0) || (b > 0);

// iii) (a + b * 100) / 10

int result3 = (a + b * 100) / 10;

// iv) a & b

int result4 = a & b;

// Display results

[Link]("Result of (a << 2) + (b >> 2): " + result1);

[Link]("Result of (a) || (b > 0): " + result2);

[Link]("Result of (a + b * 100) / 10: " + result3);

[Link]("Result of a & b: " + result4);

Output:

You might also like