Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a program in which the user can enter X amount of numbers. Once the user h

ID: 669078 • Letter: W

Question

write a program in which the user can enter X amount of numbers. Once the user has enter 10 positive numbers, he or she may not enter anymore numbers. Then the program should display the sum of those 10 number and also display each of those number.
In java language. Thanks in advance. write a program in which the user can enter X amount of numbers. Once the user has enter 10 positive numbers, he or she may not enter anymore numbers. Then the program should display the sum of those 10 number and also display each of those number.
In java language. Thanks in advance.
In java language. Thanks in advance.
In java language. Thanks in advance.

Explanation / Answer

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

public class Nos
{
public static void main(String[] args)
{
   Scanner sc = new Scanner(System.in);
   int no,sum=0,count=0,i=0;
   int ar[] = new int[10];
  
   while(count<10) //Runs till first 10 positive numbers are taken as input EXCLUDING ZERO
   {
    System.out.print(" Enter a number : ");
    no = sc.nextInt();
    //Checking if the given no is positive or not
    if(no>0)
    {
     count++;
     ar[i] = no;
     i++;
    }
   }

   //Display the positive numbers

   System.out.println(" The first ten positive numbers you have entered are : ");
   for(int j=0;j<10;j++)
    { System.out.println(" "+ar[j]+" ");
      sum = sum + ar[j]; //Calculating sum of positive numbers
    }
   System.out.println(" The sum of these positive numbers is : " +sum);
}
}