Write a class / program that takes few numbers from the input and then output the average ?
Javasearch.buggybread.com

Search Interview Questions


 3361 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Java - Interview Questions and Answers

 Q1. Write a class / program that takes few numbers from the input and then output the average ?Core Java2017-01-27 14:26:00

Ans. public class Class{
   public static void main(String[] args){
      List<Integer> collector = new ArrayList();

      Scanner scanner = new Scanner(System.in);
      int x = scanner.nextInt();
      while(x != 0){
         collector.add(x);
         x = scanner.nextInt();
      }
      System.out.println(collector.stream().collect(Collectors.averagingInt(p->((Integer)p))));
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     coding  code  collector  streams  Collectors.average     Asked in 1 Companies


Related Questions

  What is a stream and what are the types of Streams and classes of the Streams?
 Explain System.out.println ?
  What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?
  Which class is used to read streams of characters from a file?
  Which class is used to read streams of raw bytes from a file?
 How Spliterator in Java 8 different than iterator ?
 Which is better in terms of performance - Iterator or Spliterator ?
 Difference between System.out.printf and System.out.println ?
 What is the difference between the Reader/Writer java.io hierarchy and the Stream class hierarchy?
 Why is it important to close files and streams ?



Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: