MY CODE IS NOT PASSING THE TESTING.

package com.javarush.test.level07.lesson04.task01;

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader;

/ Maximum of an array of 20 numbers 1. In the method initializeArray(): 1.1. Create an array of 20 numbers 1.2. Read from the keyboard 20 numbers and fill the array with them 2. The method max(int[] array) should find the maximum number of the elements of the array /

public class Solution { public static void main(String[] args) throws Exception { int[] array = initializeArray(); int max = max(array); System.out.println(max); } public static int[] initializeArray() throws IOException { //Initialize (create and fill) an array here int[] array = new int[20]; BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); for(int i=0;i<array.length;i++) {="" string="" s="reader.readLine();" array[i]="Integer.parseInt(s);" }="" return="" null;="" }="" public="" static="" int="" max(int[]="" array)="" {="" find="" the="" max="" value="" here="" int="" max="array[0];" for(int="" i="0;i&lt;array.length;i++)" {="" if(array[i]="">max) { max=array[i]; } } return 0; } }

asked 28 Jun '15, 16:18

Abdul's gravatar image

Abdul
1
accept rate: 0%


Passed test.

 public class Solution
    {
        public static void main(String[] args) throws Exception
        {
            int[] array = initializeArray();
            int max = max(array);
            System.out.println(max);
        }
        public static int[] initializeArray() throws IOException {
            BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));
            int[] array = new int[20];
            for(int i=0; i < array.length; i++){
                array[i] = Integer.parseInt(scan.readLine());
            }
            return array;
        }

        public static int max(int[] array) {
            int max=0;
            for(int i=0; i < array.length; i++){
                if(i == 0) max = array[i];
                if(array[i] > max) max = array[i];
            }
            return max;
        }
    }
link

answered 23 May, 17:07

Igor's gravatar image

Igor
112
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×3

Asked: 28 Jun '15, 16:18

Seen: 579 times

Last updated: 23 May, 17:07