how to find highest number in list without using max function python
Numbers = [90,78,34,50,100,99]
higest_number = 0
for number in Numbers:
if number > higest_number:
higest_number = number
how to find highest number in list without using max function python
Numbers = [90,78,34,50,100,99]
higest_number = 0
for number in Numbers:
if number > higest_number:
higest_number = number
Get Max Value Element From List With Objects
public static void main(String[] args) {
Employee em = new Employee("Kiro",33,"Bulgaria"); //Creating objects
Employee em2 = new Employee("Pesho",35,"Bulgaria");
Employee em3 = new Employee("John",39,"UK");
Employee em4 = new Employee("Mike",53,"USA");
Cafe cafe = new Cafe("Malibu",4); //Creating Cafe & add the objects
cafe.addEmployee(em);
cafe.addEmployee(em2);
cafe.addEmployee(em3);
cafe.addEmployee(em4);
System.out.println("The oldest is: " + cafe.getOldestEmployee()); //prints 53
}
}
public int getOldestEmployee(){
int oldest = 0;
if (this.employees.size() > 1){
Optional<Employee> max = this.employees
.stream()
.max(Comparator.comparingInt(Employee::getAge));
oldest = max.get().getAge();
}else if (this.employees.size() == 1){
oldest = this.employees.get(0).getAge();
}
return oldest;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us