Your ddea is good, that code is working correctly.
if (getLargest1[i] > largest)
is a comparison. You are comparing the next number to the yet found biggest number.
largest = getLargest1[i];
is an assignment when you've found a number, that is bigger than the so far found biggest number.
You should move the output behind the loops, so you'd get only the desired output:
public class MyProgram
{
public static void main(String[] args)
{
new MyProgram().start();
}
public void start()
{
int[] getLargest1 = {3, 8, 4, 9, 5, 5, 23, 14};
int[] getLargest2 = {33, 23, 41, 9, 17, 51, 23, 45};
getLargestFunc(getLargest1, getLargest2);
}
private void getLargestFunc(int[] getLargest1, int[] getLargest2)
{
int largest = 0;
for (int i = 0; i < getLargest1.length; i++)
{
if (getLargest1[i] > largest)
{
largest = getLargest1[i];
}
}
System.out.println("Largest: " + largest);
for (int i = 0; i < getLargest2.length; i++)
{
if (getLargest2[i] > largest)
{
largest = getLargest2[i];
}
}
System.out.println("Largest: " + largest);
}
}