Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added programs for Java projects #97

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions SIMPLE PROJECTS/AreaOfEqTriangle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.KKDSA.Area;

import java.util.Scanner;


public class AreaOfEqTriangle {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter side:");
double side = sc.nextDouble();
double area = Math.sqrt(3)/4*side*side;
System.out.println("Area of equilateral triangle is " + area);

}
}
37 changes: 37 additions & 0 deletions SIMPLE PROJECTS/AreaOfRhombus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.KKDSA.Area;

import java.util.Scanner;

public class AreaOfRhombus {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

String option;
do {
System.out.println("Enter 1 if you have height and base");
System.out.println("Enter 2 if you have diagonals");
System.out.println("Enter 'x' to exit");
option = sc.nextLine();
switch (option) {
case "1" -> {
System.out.println("Enter height: ");
double height = sc.nextDouble();
System.out.println("Enter base:");
double base = sc.nextDouble();
double area = base * height;
System.out.println("The area of rhombus is " + area);
}
case "2" -> {
System.out.println("Enter diagonal 1: ");
double diagonal1 = sc.nextDouble();
System.out.println("Enter diagonal 2: ");
double diagonal2 = sc.nextDouble();
double area = (0.5) * diagonal1 * diagonal2;
System.out.println("The area of rhombus is " + area);
}
case "x" -> System.exit(0);
default -> System.out.println("Invalid option");
}
} while (true);
}
}
24 changes: 24 additions & 0 deletions SIMPLE PROJECTS/PerimeterOfSquare.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.KKDSA.perimeter;

import java.util.Scanner;

public class PerimeterOfSquare {
public static void main(String[] args) {
do {
Scanner sc = new Scanner(System.in);
System.out.println("Enter 1 to find perimeter.");
System.out.println("Enter 2 to exit the code.");
int option = sc.nextInt();
if(option == 1) {
System.out.println("Enter side");
double side = sc.nextDouble();
double perimeter = Math.pow(side,2);
System.out.println("The area of circle is: " + perimeter);
} else if (option == 2) {
break;
}else{
System.out.println("Invalid option");
}
} while (true);
}
}