177 Views

how to write java program to find average of two numbers


arukondavarsha 8th Nov, 2021
Answer (1)
SREYASHI SEN 8th Nov, 2021

Hello Aspirant...

Java Program

  1. import static java.lang.Float.sum;
  2. import java.util.Scanner;
  3. public class Average {
  4. public static void main(String[] args)
  5. {
  6. int n, count = 1;
  7. float  xF, averageF, sumF = 0;
  8. Scanner sc = new Scanner(System.in);
  9. System.out.println("Enter the value of n");
  10. n = sc.nextInt();
  11. while (count <= n)
  12. {
  13. System.out.println("Enter the "+count+" number?");
  14. xF = sc.nextInt();
  15. sumF += xF;
  16. ++count;
  17. }
  18. averageF = sumF/n;
  19. System.out.println("The Average is"+averageF);
  20. }
  21. }

I hope this helps.

Regards.

Related Questions

CLAT Current Affairs with GK ...
Apply
Stay updated with current affairs & check your preparation with the CLAT General Knowledge Mock Tests Ebook
CLAT English Language Mock Tests
Apply
Free Ebook - CLAT 2025 English Language questions with detailed solutions
ICFAI Business School-IBSAT 2024
Apply
9 IBS Campuses | Scholarships Worth Rs 10 CR
CLAT Legal Reasoning Mock Tests
Apply
Free Ebook - CLAT 2025 legal reasoning questions with detailed solutions
GIBS Business School Bangalor...
Apply
100% Placements with 220+ Companies
Great Lakes PGPM & PGDM 2025
Apply
Admissions Open | Globally Recognized by AACSB (US) & AMBA (UK) | 17.3 LPA Avg. CTC for PGPM 2024
View All Application Forms

Download the Careers360 App on your Android phone

Regular exam updates, QnA, Predictors, College Applications & E-books now on your Mobile

150M+ Students
30,000+ Colleges
500+ Exams
1500+ E-books