basic simple 2 programs in java 1. Average.java -- A program that takes as input
ID: 3608806 • Letter: B
Question
basic simple 2 programs in java 1. Average.java -- A program that takes as input onthe command line (i.e. in the args variable) up to 10 integers andfinds the average. Use the Integer.parseInt method to convert theString inputs to integers.2. Velocity.java -- A program that prints out thevelocity, v, of a ball that falls from a height, h, above the earth(assuming no friction, the equation is v = sqrt(2gh), where g isthe acceleration due to gravity, 9.8m/s 2). The user is prompted for the value ofh. 1. Average.java -- A program that takes as input onthe command line (i.e. in the args variable) up to 10 integers andfinds the average. Use the Integer.parseInt method to convert theString inputs to integers.
2. Velocity.java -- A program that prints out thevelocity, v, of a ball that falls from a height, h, above the earth(assuming no friction, the equation is v = sqrt(2gh), where g isthe acceleration due to gravity, 9.8m/s 2). The user is prompted for the value ofh.
Explanation / Answer
please rate - thankspart 1...
public class commandin
{
public static void main(String[] args)
{
int sum=0,i,count;
double average;
count=args.length;
if(count>10)
{count=10;
System.out.println(">10 arguments, only 1st10 will be used");
}
for(i=0;i<count;i++)
sum+=Integer.parseInt(args[i]);
System.out.println("The average is: "+(sum*1.)/count);
}
}
part 2
import java.io.*;
import java.util.*;
public class velocity
{
public static void main(String[] args)
{
double vel,g=9.8,h;
Scanner in=new Scanner(System.in);
System.out.println("Enter the height of the ball: ");
h=in.nextDouble();
vel=Math.sqrt(2*g*h);
System.out.println("The velocity of the ball is :"+vel);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.