Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. package net.ukr.vladsemenov;
  2.  
  3. import java.util.Arrays;
  4.  
  5. public class Main {
  6.  
  7. public static void main(String[] args) {
  8. int a[] = new int[] { 9, 4, 5, 76, 3, 21 };
  9. System.out.println(maxNumber(a));
  10. }
  11.  
  12. static int maxNumber(int[] a) {
  13. int max = 0;
  14. for (int i = 0; i < a.length; i++) {
  15. if (a[i] > a[i += 1]) {
  16. max = a[i];
  17. } else {
  18. max = a[i += 1];
  19. }
  20. }
  21.  
  22. return max;
  23. }
  24. }
  25.  
  26. static int maxNumber(int[] a) {
  27. int max = a[0];
  28. for (int i = 1; i < a.length; i++) {
  29. if (a[i] > max) {
  30. max = a[i];
  31. }
  32. }
  33.  
  34. return max;
  35. }
  36.  
  37. for (int i = 0; i < a.length-1; i++) {
  38. if (a[i] > a[i + 1]) {
  39. max = a[i];
  40. } else {
  41. max = a[i + 1];
  42. }
  43.  
  44. public static void main(String[] args) {
  45. int a[] = new int[] { 9, 4, 5, 76, 3, 21 };
  46. System.out.println(maxNumber(a));
  47. }
  48.  
  49. private static int maxNumber(int[] a) {
  50. int max = a[0];
  51. for (int i : a) {
  52. if (max < i) {
  53. max = i;
  54. }
  55. }
  56. return max;
  57. }
  58.  
  59. int max = Arrays.stream(a).max().getAsInt();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement