Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

TASK 3

LAIBA ZAHOOR
SP23-BSE-022
PROGRAMMING FUNDAMENTALS

Q1: Square Pattern


public class SquarePattern {
public static void main(String[] args) {
int rows = 5;
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= rows; j++) {
System.out.print("* ");
}
System.out.println();
}
}
}
Q2: Right Triangle Pattern
public class RightTrianglePattern {
public static void main(String[] args) {
int rows = 5;
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= i; j++) {
System.out.print("* ");
}
System.out.println();
}
}
}

Q3: Pyramid Pattern


public class PyramidPattern {
public static void main(String[] args) {
int rows = 5;
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= rows - i; j++) {
System.out.print(" ");
}
for (int k = 1; k <= 2 * i - 1; k++) {
System.out.print("*");
}
System.out.println();
}
}
}
Q4: Inverted Pyramid Pattern
public class InvertedPyramidPattern {
public static void main(String[] args) {
int rows = 5;
for (int i = rows; i >= 1; i--) {
for (int j = 1; j <= rows - i; j++) {
System.out.print(" ");
}
for (int k = 1; k <= 2 * i - 1; k++) {
System.out.print("*");
}
System.out.println();
}
}
}
Q5: Hollow Rectangle Pattern
public class HollowRectanglePattern {
public static void main(String[] args) {
int rows = 5;
int columns = 7;
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= columns; j++) {
if (i == 1 || i == rows || j == 1 || j == columns) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
}
}
Q6: Tangent (tan) Function:
public class TangentFunction {
public static void main(String[] args) {
double angle = 45; // Angle in degrees
double tangentValue = Math.tan(Math.toRadians(angle));
System.out.println("Tangent of " + angle + " degrees is: " + tangentValue);
}
}
Q7: Sine (sin) Function:
public class SineFunction {
public static void main(String[] args) {
double angle = 30; // Angle in degrees
double sineValue = Math.sin(Math.toRadians(angle));
System.out.println("Sine of " + angle + " degrees is: " + sineValue);
}
}
Q8: Cosine (cos) Function:
public class CosineFunction {
public static void main(String[] args) {
double angle = 60; // Angle in degrees
double cosineValue = Math.cos(Math.toRadians(angle));
System.out.println("Cosine of " + angle + " degrees is: " + cosineValue);
}
}
Q9: Ceiling Function:
public class CeilingFunction {
public static void main(String[] args) {
double number = 4.3;
double ceilingValue = Math.ceil(number);
System.out.println("Ceiling of " + number + " is: " + ceilingValue);
}
}
Q10: Square Root (sqrt) Function:
public class SquareRootFunction {
public static void main(String[] args) {
double number = 16;
double squareRootValue = Math.sqrt(number);
System.out.println("Square root of " + number + " is: " + squareRootValue);
}
}
Q11: Exponential (exp) Function:
public class ExponentialFunction {
public static void main(String[] args) {
double number = 2;
double exponentialValue = Math.exp(number);
System.out.println("Exponential of " + number + " is: " + exponentialValue);
}
}

You might also like