Commit ebd4d9e2 authored by Arsam Ali's avatar Arsam Ali

completed the remaining tasks

parent f56b7608
...@@ -4,9 +4,7 @@ import java.util.Scanner; ...@@ -4,9 +4,7 @@ import java.util.Scanner;
public class CelsiusToFahrenheit { public class CelsiusToFahrenheit {
public static void public static void main(String[] args)
main(String[] args)
{ {
Scanner input = new Scanner(System.in); Scanner input = new Scanner(System.in);
...@@ -14,9 +12,10 @@ public class CelsiusToFahrenheit { ...@@ -14,9 +12,10 @@ public class CelsiusToFahrenheit {
System.out.print("Enter a degree in Celsius: "); System.out.print("Enter a degree in Celsius: ");
double celsius = input.nextDouble(); double celsius = input.nextDouble();
// Fahrenheit=(5/9 X Celsius)+32 // Fahrenheit=(9.0/5) X Celsius +32
double fahrenheit = (9.0 / 5) * celsius + 32; double fahrenheit = (9.0 / 5) * celsius + 32;
System.out.println(celsius + " Celsius is " + fahrenheit + " Fahrenheit"); System.out.println(celsius + " Celsius is " + fahrenheit + " Fahrenheit");
} }
} }
...@@ -4,22 +4,20 @@ import java.util.Scanner; ...@@ -4,22 +4,20 @@ import java.util.Scanner;
public class FutureDay { public class FutureDay {
public static void main(String[] args) public static void main(String[] args) {
{
Scanner input = new Scanner(System.in); 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(); 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 daysElapsed = input.nextInt();
int futureDay = (today + daysElapsed) % 7; int futureDay = (today + daysElapsed) % 7;
String[] daysOfWeek = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; String[] daysOfWeek = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
System.out.println("Today is " + daysOfWeek[today] + " and the future day is " + daysOfWeek[futureDay]); System.out.println("Today is " + daysOfWeek[today] + " and the future day is " + daysOfWeek[futureDay]);
} }
......
...@@ -10,14 +10,12 @@ public class JavaDiagram { ...@@ -10,14 +10,12 @@ public class JavaDiagram {
"J J AAAAA V V AAAAA", "J J AAAAA V V AAAAA",
"J A A V A A" "J A A V A A"
}; };
for (String row:rows){
for (String row : rows) { for (char ch : row.toCharArray()){
for (char ch : row.toCharArray()) { System.out.print(ch+ " ");
System.out.print(ch + " ");
} }
System.out.println(); System.out.println();
} }
} }
} }
...@@ -6,13 +6,9 @@ public class MonthIntoEnglish { ...@@ -6,13 +6,9 @@ public class MonthIntoEnglish {
public static void main(String[] args) { public static void main(String[] args) {
// String[] months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; 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];
// Random random = new Random(); System.out.println("Random month: " + monthName);
// int monthNumber = random.nextInt(12) + 1;
//
//
// String monthName =
} }
} }
...@@ -16,9 +16,10 @@ public class PopulationOfUs { ...@@ -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 // 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; 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); long newPopulation = (long) (currentPopulation + populationChangePerYear * year);
System.out.println("Year " + year + ": " + newPopulation); System.out.println("Year " + year + ": " + newPopulation);
} }
} }
} }
...@@ -14,24 +14,24 @@ public class RevisedBMI { ...@@ -14,24 +14,24 @@ public class RevisedBMI {
System.out.print("Enter inches: "); System.out.print("Enter inches: ");
int inches = input.nextInt(); 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; 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 // 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); double bmi = weightInPounds * 0.45359237 / (heightInMeters * heightInMeters);
String interpretation = null; String Level = null;
if (bmi < 18.5) { if (bmi < 18.5) {
interpretation = "Underweight"; Level = "Underweight";
} else if (bmi < 25) { } else if (bmi < 25) {
interpretation = "Normal"; Level = "Normal";
} else if (bmi < 30) { } else if (bmi < 30) {
interpretation = "Overweight"; Level = "Overweight";
} else { } else {
interpretation = "Obese"; Level = "Obese";
} }
System.out.println("BMI is " + bmi); System.out.println("BMI is " + bmi);
System.out.println("Interpretation: " + interpretation); System.out.println("Level: " + Level);
} }
} }
...@@ -15,23 +15,23 @@ public class SortThreeIntegers { ...@@ -15,23 +15,23 @@ public class SortThreeIntegers {
int temp; int temp;
if (num1 > num2) { if(num1>num2) {
temp = num1; temp = num1;
num1 = num2; num1 = num2;
num2 = temp; num2 = temp;
} }
if (num1 > num3) { if(num1>num3) {
temp = num1; temp = num1;
num1 = num3; num1 = num3;
num3 = temp; num3 = temp;
} }
if (num2 > num3) { if(num2>num3) {
temp = num2; temp = num2;
num2 = num3; num2 = num3;
num3 = temp; num3 = temp;
} }
System.out.println("Integers in non-decreasing order: " + num1 + ", " + num2 + ", " + num3); System.out.println("Integers in non-decreasing order: " + num1 + ", " + num2 + ", " + num3);
} }
......
...@@ -4,19 +4,22 @@ import java.util.Scanner; ...@@ -4,19 +4,22 @@ import java.util.Scanner;
public class SumTheDigits { public class SumTheDigits {
public static void public static void main(String[] args)
main(String[] args)
{ {
// Scanner input = new Scanner(System.in); Scanner input = new Scanner(System.in);
//
// System.out.print("Enter a number between 0 and 1000: "); System.out.print("Enter a number between 0 and 1000: ");
// int number = input.nextInt(); int inputNumber = input.nextInt();
//
// int sumOfDigits = 0; int sumOfDigits = 0;
// while (number > 0) { while (inputNumber > 0) {
// int 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 { ...@@ -7,11 +7,9 @@ public class TableofAndNumeric {
for (int a = 1; a <= 4; a++) { for (int a = 1; a <= 4; a++) {
int a_sq = a * a;
int a_squared = a * a; int a_cube = a * a * a;
int a_cubed = a * a * a; System.out.println(a + "\t" + a_sq + "\t" + a_cube);
System.out.println(a + "\t" + a_squared + "\t" + a_cubed);
} }
} }
} }
...@@ -15,8 +15,24 @@ public class TriangleArea { ...@@ -15,8 +15,24 @@ public class TriangleArea {
double x3 = input.nextDouble(); double x3 = input.nextDouble();
double y3 = 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