Commit ebd4d9e2 authored by Arsam Ali's avatar Arsam Ali

completed the remaining tasks

parent f56b7608
......@@ -4,9 +4,7 @@ import java.util.Scanner;
public class CelsiusToFahrenheit {
public static void
main(String[] args)
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
......@@ -14,9 +12,10 @@ public class CelsiusToFahrenheit {
System.out.print("Enter a degree in Celsius: ");
double celsius = input.nextDouble();
// Fahrenheit=(5/9 X Celsius)+32
// Fahrenheit=(9.0/5) X Celsius +32
double fahrenheit = (9.0 / 5) * celsius + 32;
System.out.println(celsius + " Celsius is " + fahrenheit + " Fahrenheit");
}
}
......@@ -4,15 +4,13 @@ import java.util.Scanner;
public class FutureDay {
public static void main(String[] args)
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter today's day (0 for Sunday, 1 for Monday, ..., 6 for Saturday): ");
System.out.print("Enter today's day");
int today = input.nextInt();
System.out.print("Enter the number of days elapsed since today: ");
System.out.print("Enter the number of days");
int daysElapsed = input.nextInt();
int futureDay = (today + daysElapsed) % 7;
......
......@@ -10,14 +10,12 @@ public class JavaDiagram {
"J J AAAAA V V AAAAA",
"J A A V A A"
};
for (String row : rows) {
for (char ch : row.toCharArray()) {
System.out.print(ch + " ");
for (String row:rows){
for (char ch : row.toCharArray()){
System.out.print(ch+ " ");
}
System.out.println();
}
}
}
......@@ -6,13 +6,9 @@ public class MonthIntoEnglish {
public static void main(String[] args) {
// String[] months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
//
//
// Random random = new Random();
// int monthNumber = random.nextInt(12) + 1;
//
//
// String monthName =
String[] months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
int monthNumber = new Random().nextInt(12);
String monthName = months[monthNumber - 1];
System.out.println("Random month: " + monthName);
}
}
......@@ -16,9 +16,10 @@ public class PopulationOfUs {
// Population Change Per Year=(Births Per Second−Deaths Per Second+Immigrants Per Second)×Seconds Per Day×Days Per Year
double populationChangePerYear = (BIRTHS_PER_SECOND - DEATHS_PER_SECOND + IMMIGRANTS_PER_SECOND) * SECONDS_PER_DAY * DAYS_PER_YEAR;
for (int year = 1; year <= 5; year++) {
for (int year = 1; year <=5; year++) {
long newPopulation = (long) (currentPopulation + populationChangePerYear * year);
System.out.println("Year " + year + ": " + newPopulation);
}
}
}
......@@ -14,24 +14,24 @@ public class RevisedBMI {
System.out.print("Enter inches: ");
int inches = input.nextInt();
// Height in Meters=(Feet×0.3048)+(Inches×0.0254)
// Height in Meters=(Feet*12*.3048)+(Inches×0.0254)
double heightInMeters = (feet * 12 + inches) * 0.0254;
// Calculate BMI & The constant 0.45359237 is the conversion factor since 1 pound is approximately equal to 0.45359237 kilograms
double bmi = weightInPounds * 0.45359237 / (heightInMeters * heightInMeters);
String interpretation = null;
String Level = null;
if (bmi < 18.5) {
interpretation = "Underweight";
Level = "Underweight";
} else if (bmi < 25) {
interpretation = "Normal";
Level = "Normal";
} else if (bmi < 30) {
interpretation = "Overweight";
Level = "Overweight";
} else {
interpretation = "Obese";
Level = "Obese";
}
System.out.println("BMI is " + bmi);
System.out.println("Interpretation: " + interpretation);
System.out.println("Level: " + Level);
}
}
......@@ -15,19 +15,19 @@ public class SortThreeIntegers {
int temp;
if (num1 > num2) {
if(num1>num2) {
temp = num1;
num1 = num2;
num2 = temp;
}
if (num1 > num3) {
if(num1>num3) {
temp = num1;
num1 = num3;
num3 = temp;
}
if (num2 > num3) {
if(num2>num3) {
temp = num2;
num2 = num3;
num3 = temp;
......
......@@ -4,19 +4,22 @@ import java.util.Scanner;
public class SumTheDigits {
public static void
main(String[] args)
public static void main(String[] args)
{
// Scanner input = new Scanner(System.in);
//
// System.out.print("Enter a number between 0 and 1000: ");
// int number = input.nextInt();
//
// int sumOfDigits = 0;
// while (number > 0) {
// int
// }
Scanner input = new Scanner(System.in);
System.out.print("Enter a number between 0 and 1000: ");
int inputNumber = input.nextInt();
int sumOfDigits = 0;
while (inputNumber > 0) {
int digit = inputNumber % 10;
sumOfDigits += digit;
inputNumber /= 10;
}
System.out.println("The sum of the digits is " + sumOfDigits);
}
}
......@@ -7,11 +7,9 @@ public class TableofAndNumeric {
for (int a = 1; a <= 4; a++) {
int a_squared = a * a;
int a_cubed = a * a * a;
System.out.println(a + "\t" + a_squared + "\t" + a_cubed);
int a_sq = a * a;
int a_cube = a * a * a;
System.out.println(a + "\t" + a_sq + "\t" + a_cube);
}
}
}
......@@ -15,8 +15,24 @@ public class TriangleArea {
double x3 = input.nextDouble();
double y3 = input.nextDouble();
// Calculate side lengths using the distance formula
double side1 = calculateSideLength(x1, y1, x2, y2);
double side2 = calculateSideLength(x2, y2, x3, y3);
double side3 = calculateSideLength(x3, y3, x1, y1);
// Calculate semi-perimeter
double s = (side1 + side2 + side3) / 2;
// Calculate area using Heron's formula
double area = Math.sqrt(s * (s - side1) * (s - side2) * (s - side3));
System.out.println("The area of the triangle is " + area);
}
// Helper method to calculate side length using the distance formula
private static double calculateSideLength(double x1, double y1, double x2, double y2) {
return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment