I\'m in java one and i\'m sctuck with this program. please can sombody help me?
ID: 3675818 • Letter: I
Question
I'm in java one and i'm sctuck with this program. please can sombody help me? please follow the directions.thank you.(answers as soon as posible)
Programming Concepts
1. Arrays
2. forloops
Exercise Location
For this exercise, you will copy a program from my directory into yours. It doesn't matter what directory this exercise is located in. You will need to copy this command and paste it into Loki:
cp ~lkoperski/1404_Lab/Exercises/Exercise08.java .
Exercise Description
You will initialize an array with the numbers 5, 29, -16, 50, and 0. After that, you will print the array and calculate the min/max, and print that out.
Exercise Requirements
1. When printing out the array, make sure to print out each number, followed by a comma and a space.
output example
user@loki:~$ java Exercise08
Here is the array: [5, 29, -16, 50, 0]
Min: -16
Max: 50
Explanation / Answer
public class minMax{
public static void main(String []args){
int numbers[] = new int[]{32,43,53,54,32,65,63,98,43,23,-5,0};
int lastOne =numbers[numbers.length-1];
if(lastOne==0)
{
int smallest = numbers[0];
int largetst = numbers[0];
for(int i=1; i< numbers.length; i++)
{
if(numbers[i] > largetst)
largetst = numbers[i];
else if (numbers[i] < smallest)
smallest = numbers[i];
}
System.out.println("Largest Number is : " + largetst);
System.out.println("Smallest Number is : " + smallest);
}
}
}
OutPut:
Largest Number is : 98
Smallest Number is : -5
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.