Please help me out with this questions
Answers
Answer:
4)
import java.util.Scanner;
class Trees
{
public static void main(String[] args)
{
//Declaration
Scanner input = new Scanner(System.in);
double h1, h2, average;
//Prompt and accept the heights of the trees
System.out.println("Enter height of the first tree: ");
h1 = input.nextDouble();
System.out.println("Enter height of the second tree: ");
h2 = input.nextDouble();
//Calculate average of the height of the 2 trees
average = (h1 + h2)/2.0;
//Display
System.out.println("Average height of the 2 tress is = " + average);
if (h1 > h2)
{
System.out.println("First tree is taller with height " + h1);
}
if (h1 < h2)
{
System.out.println("Second tree is taller with height " + h2);
}
else
{
System.out.println("Height of the 2 trees is the same, which is " +
h1 + "metres");
}
}
}
5)
import java.util.Scanner;
class Factors
{
public static void main(String[] args)
{
//Declaration
Scanner input = new Scanner(System.in);
int p, q;
//Prompt and accept two numbers from user
System.out.println("Enter the 1st number: ");
p = input.nextInt();
System.out.println("Enter the 2nd number: ");
q = input.nextInt();
//Display
System.out.println("Average height of the 2 tress is = " + average);
if (p % q == 0)
{
System.out.println(q + " is a factor of " + p);
}
else
{
System.out.println(q + " is not a factor of " + p);
}
}
}