Question
java in simple way
pla help me
1. Write a program that uses a while loop to read 10 integer numbers from file numbers.in and prints their sum and average
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.*;
import java.lang.*;
import java.io.*;


class Chegg
{
   public static void main (String[] args) throws FileNotFoundException
   {
       int sum=0;
       double avg=0;
       File file = new File("C:/Users/Gaurav/Documents/input.txt");
       Scanner scanner = new Scanner(file);
       while (scanner.hasNext())
       {
           if(scanner.hasNextInt())
           {
               int num=scanner.nextInt();
               sum=sum+num;
           }
           else
           scanner.next();
       }
       avg=(sum*1.0)/10;
       System.out.println("The sum is "+sum+" and average is "+avg);
      
   }
}

class Chegg public static void main (String[] args) throws FileNotFoundException int sum=0; double avg=0; File file = new Fil

Sample Input:-

Sample Output:-

The sum is 55 and average is 5.5

Add a comment
Know the answer?
Add Answer to:
java in simple way pla help me 1. Write a program that uses a while loop...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT