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

1. Using Java program: Write a simple program to sum data points. Create a Scann

ID: 3552906 • Letter: 1

Question

1. Using Java program: Write a simple program to sum data points. Create a Scanner object console to read data from the console. First read the number of data points to be summed. Then ask for each data point one at a time as you are accumulating the sum in a for loop. This only has a main method. You should not have any methods other than the main method. the sum is printed out using Sytem.out.printf() with a format of %.3f. Also notice that the prompt includes the current data point number (the value of i in the for loop) so the user knows exactly which data point to provide.


2. Using Java program: Write a simple program to take the product of a set of data points. Create a Scanner object
console to read data from the console. First read the number of data points to be multiplied together. Then ask for each data point one at a time as you are accumulating the product in a for loop. This ONLY has a main method. You should not have any methods other than the main method. Notice that the sum is printed out using Sytem.out.printf() with a format of %.3f. Also notice that the prompt includes the current data point number (the value of i in the for loop) so the user knows exactly which data point to provide

Explanation / Answer

import java.util.Scanner;

class sumNumbers
{
    public static void main (String args[])
    {
        int dataPoint = 0;
        int sum = 0;
        Scanner input = new Scanner (System.in);

        System.out.println("How many data point do you like to enter: ");
        dataPoint = input.nextInt();

        for (int i = 0; i < dataPoint; i++)
        {
            System.out.println("Please enter the value of data point " + (i + 1));
            sum = sum + input.nextInt();
        }

        System.out.println("The sum is " + sum);

    }
}


import java.util.Scanner;

class multipleNumbers
{
    public static void main (String args[])
    {
        int dataPoint = 0;
        int sum = 1;
        Scanner input = new Scanner (System.in);

        System.out.println("How many data point do you like to enter: ");
        dataPoint = input.nextInt();

        for (int i = 0; i < dataPoint; i++)
        {
            System.out.println("Please enter the value of data point " + (i + 1));
            sum = sum * input.nextInt();
        }

        System.out.println("The product is " + sum);

    }
}