import java.util.*;
/**
*There is a given array with the different ages of some event.
*Part A: Find the highest
*Part B: Search if the array has the age of 75,31,or 89
*/
public class FreeResponse
{
public static void main(String[] args)
{
ArrayList<Integer> ages = new ArrayList<Integer>();
ages.add(37);
ages.add(32);
ages.add(59);
ages.add(72);
ages.add(31);
ages.add(42);
ages.add(51);
ages.add(90);
ages.add(6);
int high = 0;
int temp = 0;
//part a
for (int i = 0; i < ages.size(); i++) {
if( ages.get(i) > temp){
temp = ages.get(i);
high = ages.get(i);
}
}
System.out.println(high);
//part b
int test1 = 75;
int test2 = 31;
int test3 = 89;
for (int i = 0; i < ages.size(); i++) {
if( ages.get(i) == test1){
System.out.println("A person 75 years old was there");
}
if( ages.get(i) == test2){
System.out.println("A person 31 years old was there");
}
if( ages.get(i) == test3){
System.out.println("A person 75 years old was there");
}
}
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.