Answer the question
In order to leave comments, you need to log in
How to find the largest element in an array and display everything after it?
I'm already sweaty sitting with this.
I need the index of the maximum element, but how to get it - I'll never know. Google - I did not find it.
package com.winderton.study.mark;
public class Pascal2 {
public static void main(String args[]) {
int array[] = {1,2,6,-4,4,5,-2,-5,2,3};
int max = 0;
for (int i = 0; i < array.length; i++) {
if (array[i] > max) {
max = array[i];
}
for (int j = i; j < array.length; j++){
System.out.println(array[j]);
}
}
}
}
Answer the question
In order to leave comments, you need to log in
int max = array[0];
int maxIndex = 0;
for (int index = 0; index < array.length; index++) {
if (array[index] > max) {
max = array[index];
maxIndex = index;
}
}
for (int index = maxIndex; index < array.length; index++){
System.out.println(array[index]);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question