1. Write a program to input three angles of a triangle and check whether construction is possible or not. If possible then check and display whether it V. Unsolved Java Programs: an acute-angled triangle, right-angled or an obtuse-angled triangle. Otherwise display 'A Triangle is not possible'. Sample Input: Enter three angles: 40, 50, 90 Sample Output: Right-Angled Triangle 2. Write a program to input the cost price and the selling price of an article the selling price is more than the cost price then calculate and display actl the profit and profit per cent otherwise, calculate and display the actual los and loss per cent. If the cost price and the selling price are equal, the progran displays the message 'Neither profit nor loss'. 3. Write a program to input three numbers and check whether they are eque or not. If they are unequal numbers then display the greatest among them otherwise, display the message 'All the numbers are equal'. Sample Input: 34, 87, 61 Sample Output: Greatest number: 87 Sample Input: 81, 81, 81 Sample Output: All the numbers are equal. 4. Write a program to accept a number and check whether the number is divisib by 3 as well as 5. Otherwise, decide: (a) Is the number divisible by 3 and not by 5? (b) Is the number divisible by 5 and not by 3? (c) Is the number neither divisible by 3 nor by 5? The program displays the message accordingly.
Answers
Hope it helps ^_^
This single question contains 4 questions and so the answer
These programs are in Java
1. Triangle Checker
import java.util.Scanner;
public class TriangleTest{
public static void main(String [] args){
System.out.println("Enter the 3 angles of the Triangle");
Scanner sc = new Scanner(System.in);
double a1 = sc.nextDouble();
double a2 = sc.nextDouble();
double a3 = sc.nextDouble();
boolean result;
if (a1 + a2 + a3 == 180){
result = true;
}
else{
result = false;
}
if (result == true){
//For Equilateral Triangle
if (a1 == 60 && a2 == 60 && a3 == 60)
System.out.println("The given angles will make an Equilateral Triangle");
//For Obtuse Angled Triangle
if (a1 > 90 || a2 > 90 || a3 > 90)
System.out.println("The given angles will make an Obtuse Angled Triangle");
//For Acute Angled Triangle
if (a1 < 90 && a2 < 90 && a3 < 90 && a1 != 60 && a2 != 60 && a3 != 60)
System.out.println("The given angles will make an Acute Angled Triangle");
//For Right Angled Triangle
if (a1 == 90 || a2 == 90 || a3 == 90)
System.out.println("The given sides will make a Right Angled Triangle");
}
else if (result == false){
System.out.println("The given angles cannot make a Triangle");
}
}
}
2. Profit/Loss Calculator
import java.util.Scanner;
public class Profit_And_Loss_Calculator{
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
double cp, sp, gain, loss;
//Taking input
System.out.print("Enter the Cost Price: ");
cp = sc.nextDouble();
System.out.print("Enter the Selling Price: ");
sp = sc.nextDouble();
//Main part comes here
if (cp > sp && cp >= 0 && sp >= 0){
loss = cp - sp;
double Loss_Percentage = (loss/cp) * 100;
System.out.println("Loss: " + loss);
System.out.println("Loss(%): " + Loss_Percentage);
}
else if (cp < sp && cp >= 0 && sp >= 0){
gain = sp - cp;
double Gain_Percentage = (gain/cp) * 100;
System.out.println("Gain: " + gain);
System.out.println("Gain(%): " + Gain_Percentage);
}
else if (cp == sp && cp >= 0 && sp >= 0){
System.out.println("There is no Gain or Loss");
}
else if (cp < 0 || sp < 0){
System.out.println("Invalid Input *_*");
}
}
}
3. Useless Program
import java.util.Scanner;
public class Useless_Program{
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
double n1, n2, n3;
System.out.println("This is a useless program which tells whether 3 numbers are equal or not");
System.out.println("And prints the greatest number among them if they aren't equal");
System.out.print("Enter the first number: ");
n1 = sc.nextDouble();
System.out.print("Enter the second number: ");
n2 = sc.nextDouble();
System.out.print("Enter the third number: ");
n3 = sc.nextDouble();
if (n1 == n2 && n2 == n3 && n1 == n3){
System.out.println("These numbers are equal");
}
else if (n1 > n2 && n1 > n3){
System.out.println("The largest number is " + n1);
}
else if (n2 > n1 && n2 > n3){
System.out.println("The largest number is " + n2);
}
else if (n3 > n2 && n3 < n1){
System.out.println("The largest number is " + n3);
}
}
}
4. 3 & 5 Multiple Teller
import java.util.Scanner;
public class Diviser_3_5 {
public static void main (String [] args){
//Taking input from the user
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number to know if it's divisible by 3 or 5: ");
double num = sc.nextDouble();
//Main part comes here
boolean correct = num % 3 == 0 && num % 5 == 0;
if (correct == true)
System.out.println("Wow, this number is divisible by both 3 and 5!");
else{
if (num % 3 == 0 && num % 5 != 0){
System.out.println("This number is divisible by 3 but not 5");
}
if (num % 3 != 0 && num % 5 == 0){
System.out.println("This number is divisible by 5 but not 3");
}
if (num % 3 != 0 && num % 5 != 0 ){
System.out.println("This number is not divisible by either 3 or 5");
}
}
}
}
It's my longest answer till now
It's not my most perfect answer because it doesn't contain outputs. If I added the outputs, my answer exceeded the maximum word limit
Thanks for reading till here ˶ᵔ ᵕ ᵔ˶