Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.ukr.vladsemenov;
- import java.util.Arrays;
- public class Main {
- public static void main(String[] args) {
- int a[] = new int[] { 9, 4, 5, 76, 3, 21 };
- System.out.println(maxNumber(a));
- }
- static int maxNumber(int[] a) {
- int max = 0;
- for (int i = 0; i < a.length; i++) {
- if (a[i] > a[i += 1]) {
- max = a[i];
- } else {
- max = a[i += 1];
- }
- }
- return max;
- }
- }
- static int maxNumber(int[] a) {
- int max = a[0];
- for (int i = 1; i < a.length; i++) {
- if (a[i] > max) {
- max = a[i];
- }
- }
- return max;
- }
- for (int i = 0; i < a.length-1; i++) {
- if (a[i] > a[i + 1]) {
- max = a[i];
- } else {
- max = a[i + 1];
- }
- public static void main(String[] args) {
- int a[] = new int[] { 9, 4, 5, 76, 3, 21 };
- System.out.println(maxNumber(a));
- }
- private static int maxNumber(int[] a) {
- int max = a[0];
- for (int i : a) {
- if (max < i) {
- max = i;
- }
- }
- return max;
- }
- int max = Arrays.stream(a).max().getAsInt();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement