0

NEED HELP PLZ!!!

so in my code i need to make it that it prints the larger number but it always print the small one i check and all my friend got it right and i got the same code this is the structure public class AlgFindGreatestValue { public static void main (String arg[]) { int [] dan = {150,250,350,450}; int greater = 0; int index = 0; int size = dan.length; System.out.println("SEARCH ALGORITHM"); System.out.println("FIND THE GREATEST VALUE"); System.out.println(dan[0]); greater = dan[0]; size = size -1 ; while ( index < size ); { index = index +1 ; System.out.println(dan[index]); if ( dan [index]> greater) { greater = dan [index]; } } System.out.println("The highest is: "+" "+greater); } }

12th Dec 2016, 3:20 PM
Daniel Gonzalez Garcia
Daniel Gonzalez Garcia - avatar
3 odpowiedzi
+ 1
Remove the Semi-Colon in while loop.. Your code will work fine.. while(index<size) {.... ... ... }
12th Dec 2016, 4:07 PM
Kaushik M
Kaushik M - avatar
0
If you want to achive max and min values here's the simple way to do it import java.util.Arrays; public class Program { public static void main(String[] args) { int arr[] = {12,50,2,60,7}; Arrays.sort(arr); System.out.println("Min value "+arr[0]); System.out.println("Max value "+arr[arr.length-1]); } } Output Min value 2 Max value 60 Description The java.util.Arrays.sort(int[]) method sorts the specified array of ints into ascending numerical order.
12th Dec 2016, 4:03 PM
Vipul Walia
Vipul Walia - avatar
0
thanks man but its already done XD.
6th Feb 2017, 4:24 PM
Daniel Gonzalez Garcia
Daniel Gonzalez Garcia - avatar