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

Java Practical Programs

The document contains practical Java programs for BCA 2nd semester, covering topics such as basic syntax, bitwise operators, swapping variables, checking even/odd numbers, calculating factorials, generating multiplication tables, and creating pyramid patterns. Each program includes necessary imports, user input handling, and output statements. The examples demonstrate fundamental programming concepts and techniques in Java.

Uploaded by

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

Java Practical Programs

The document contains practical Java programs for BCA 2nd semester, covering topics such as basic syntax, bitwise operators, swapping variables, checking even/odd numbers, calculating factorials, generating multiplication tables, and creating pyramid patterns. Each program includes necessary imports, user input handling, and output statements. The examples demonstrate fundamental programming concepts and techniques in Java.

Uploaded by

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

Java Practical Programs (BCA 2nd Semester)

1. Declaration & Basic Syntax


public class Exp1 {
public static void main(String[] args) {
int a = 10;
float b = 5.5f;
char c = 'A';

[Link]("Integer: " + a);


[Link]("Float: " + b);
[Link]("Character: " + c);
}
}

2. Bitwise Operators
import [Link];

public class Exp2 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int a = [Link]();
int b = [Link]();

[Link]("AND: " + (a & b));


[Link]("OR: " + (a | b));
[Link]("XOR: " + (a ^ b));
}
}

3. Swapping without 3rd variable


import [Link];

public class Exp3 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int a = [Link]();
int b = [Link]();

a = a + b;
b = a - b;
a = a - b;

[Link]("After swap: " + a + " " + b);


}
}

4. Even/Odd Program
import [Link];

public class Exp4 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();

if (n % 2 == 0)
[Link]("Even");
else
[Link]("Odd");
}
}

5. Factorial
import [Link];

public class Exp5 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
int fact = 1;

for (int i = 1; i <= n; i++)


fact *= i;

[Link]("Factorial: " + fact);


}
}

6. Multiplication Table
import [Link];

public class Exp6 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();

for (int i = 1; i <= 10; i++)


[Link](n + " x " + i + " = " + (n*i));
}
}

7. Pyramid Pattern
import [Link];

public class Exp7 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();

for (int i = 1; i <= n; i++) {


for (int j = i; j < n; j++)
[Link](" ");
for (int j = 1; j <= i; j++)
[Link]("* ");
[Link]();
}
}
}

You might also like