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

6. Sets of data values of type double are to be read. There is no invalid value

ID: 3635895 • Letter: 6

Question

6. Sets of data values of type double are to be read. There is no invalid value available that could be used as a sentinel. Therefore, each value of type double is followed on the same line by an int value.
The int is equal to 0 except that on the last line of each dataset, the int is equal to 1 to signal the end of that dataset. For example:
13.3 0
-97.2 0
34.6 0
76.2 1 ? End of dataset #1
56.0 0 ? Beginning of next dataset
Write a public static method readOneDataset that will read in one dataset of double values, store the values into an array parameter dA[], and return the number of values read. In the example above, the method would read and store 13.3,
-97.2, 34.6, and 76.2 into dA[0] through dA[3], and return the value 4 . (The int values are discarded.) The method must check that the array dA[] is large enough and terminate if not; do not do any other defensive programming.
This is only an example; your method must be general!

public static int readOneDataset(Scanner scan, double[] dA)
{

Explanation / Answer

please rate - thanks

your example didn't have a prompt, so I didn't provide one

import java.util.*;
public class main
{
public static void main(String [] args)
{Scanner in=new Scanner(System.in);
double []a=new double[20];
int n=readOneDataset(in,a);
System.out.println("You read the numbers: ");
for(int i=0;i<n;i++)
    System.out.print(a[i]+" ");
    System.out.println();
   }
public static int readOneDataset(Scanner scan, double[] dA)
{int i=0,n;
while(i<dA.length)
    {dA[i]=scan.nextDouble();
    if(scan.nextInt()==1)
          return i+1;
    i++;
    }
return i;
}
}


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote