Create a new Jave program called Examine2. Modify the below Java code Examine1 to use an if…if/else statement. Check each value entered by the user to determine if the user entered a negative number. If so, program should count each negative number entered. Once user has entered all numbers, program should print the total negative numbers entered by user. The program should print the average using the printf command and the number of negative numbers entered. *note: you may include or exclude the negative numbers with your calculation. import java.util.Scanner; public class Examine1 { public static void main(String[] args) { int n, sum = 0; float average; //for calculating average of all inputs Scanner s = new Scanner(System.in); //Scanner for read input from user System.out.printf("How many numbers you want to enter:\n"); n = s.nextInt(); //taking user input for how many numbers int a[] = new int[n]; System.out.printf("Enter all the numbers:\n"); for(int i = 0; i < n ; i++) { a[i] = s.nextInt(); sum = sum + a[i]; } System.out.printf("\nSum:"+sum); average = (float)sum / n; //calculating average System.out.printf("\nAverage:"+average ); } } Thank you, I'm having trouble modifying this code.
Max Function
Statistical function is of many categories. One of them is a MAX function. The MAX function returns the largest value from the list of arguments passed to it. MAX function always ignores the empty cells when performing the calculation.
Power Function
A power function is a type of single-term function. Its definition states that it is a variable containing a base value raised to a constant value acting as an exponent. This variable may also have a coefficient. For instance, the area of a circle can be given as:
Create a new Jave
Modify the below Java code Examine1 to use an if…if/else statement.
Check each value entered by the user to determine if the user entered a negative number. If so, program should count each negative number entered.
Once user has entered all numbers, program should print the total negative numbers entered by user.
The program should print the average using the printf command and the number of negative numbers entered.
*note: you may include or exclude the negative numbers with your calculation.
import java.util.Scanner;
public class Examine1 {
public static void main(String[] args)
{
int n, sum = 0;
float average; //for calculating average of all inputs
Scanner s = new Scanner(System.in); //Scanner for read input from user
System.out.printf("How many numbers you want to enter:\n");
n = s.nextInt(); //taking user input for how many numbers
int a[] = new int[n];
System.out.printf("Enter all the numbers:\n");
for(int i = 0; i < n ; i++)
{
a[i] = s.nextInt();
sum = sum + a[i];
}
System.out.printf("\nSum:"+sum);
average = (float)sum / n; //calculating average
System.out.printf("\nAverage:"+average );
}
}
Thank you, I'm having trouble modifying this code.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images