Computer Science, asked by rishitkumar14dec2006, 7 hours ago

Write a program in Java to input a series of numbers one by one to print the count and average of those numbers which have 3 as their last digit. The process of inputting numbers should stop if the number inputted by the user is a negative number.​

Answers

Answered by manishajadhao251
2

Answer:

Scanner scanner = new Scanner(System.in);

int sum = 0;

System.out.println("Input a number: ");

sum = sum + Integer.valueOf(scanner.nextLine());

System.out.println("Input a number: ");

sum = sum + Integer.valueOf(scanner.nextLine());

System.out.println("Input a number: ");

sum = sum + Integer.valueOf(scanner.nextLine());

System.out.println("Input a number: ");

sum = sum + Integer.valueOf(scanner.nextLine());

System.out.println("Input a number: ");

sum = sum + Integer.valueOf(scanner.nextLine());

System.out.println("The sum of the

Answered by prakharuts015
0

Answer:

import java.util.Scanner;

public class KboatNumbers

{

   public static void main(String args[]) {        

       Scanner in = new Scanner(System.in);

       System.out.println("Enter the numbers: ");

       int count = 0;

       double sum =0;        

       while (true) {

           int n = in.nextInt();

           if (n < 0) {

               break;

           }  

           int ld = n % 10;      

           if (ld ==3) {

               count++;

               sum  += n;

           }

       }  

       double avg =sum / count;

         System.out.println("Count= " + count);

       System.out.println("Average= " + avg);

   }

}

Output:

Enter the number:

10\\13\\15\\33\\63\\-8\\

Count =3\\\\ Average=36.3333333

Explanation:

Java input and output is a requisite concept when working on java programming. It incorporates elements as input, output, and stream. The input is the data that we give to the program. The output is the data we experience from the program in the form of results. In Java, there are four different ways of reading input from the user in the be in charge of line environment(console).

Hence, the correct answer is:

import java .util. Scanner;

public class KboatNumbers

{

   public static void main(String args[]) {        

       Scanner in = new Scanner(System.in);

       System.out.println("Enter the numbers: ");

       int count = 0;

       double sum =0;        

       while (true) {

           int n = in.nextInt();

           if (n < 0) {

               break;

           }  

           int ld = n % 10;      

           if (ld ==3) {

               count++;

               sum  += n;

           }

       }  

       double avg =sum / count;

         System.out.println("Count= " + count);

       System.out.println("Average= " + avg);

   }

}

Output:

Enter the number:

10\\13\\15\\33\\63\\-8\\

Count =3\\\\ Average=36.3333333

#SPJ3

Similar questions