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

I\'m trying to figure out how to make code in JAVA that will allow a user to inp

ID: 3538309 • Letter: I

Question

I'm trying to figure out how to make code in JAVA that will allow a user to input a string of numbers (e.g. 15,16,18,19) and me to take those numbers and do stuff with it, like find the standard deviation, min, max, and mean of the set of numbers.

I'm used to Python and I've just learned how to use JAVA so I'm pretty awful as you can see. This is my current working code:


import java.io.*;


public class computation {

//main method starts

public static void main (String[] args) throws Exception {

  

//create text input reader

InputStreamReader get = new InputStreamReader(System.in);

BufferedReader got = new BufferedReader(get);

//create a text printer

PrintWriter send = new PrintWriter(System.out,true);

//defining a string type variable for user input

String answer1;

//asks the user if they want to input data from keyboard

String question = "Do you want to input data manually? Enter y or n";

send.println(question);

//system reads user input

answer1 = got.readLine();

if (answer1.equals("y")) {

send.println("Enter numbers separated by commas");

String datacurrent = got.readLine();

double dataarray = Double.parseDouble(datacurrent);

} //end of "y" if

if (answer1.equals("n")) {

send.println("Enter the path of your data file");

} //end of "n" if

} //end of main method

} //end of class computation

Explanation / Answer

import java.io.*;


public class computation {

//main method starts

public static void main (String[] args) throws Exception {

  

//create text input reader

InputStreamReader get = new InputStreamReader(System.in);

BufferedReader got = new BufferedReader(get);

//create a text printer

PrintWriter send = new PrintWriter(System.out,true);

//defining a string type variable for user input

String answer1;

//asks the user if they want to input data from keyboard

String question = "Do you want to input data manually? Enter y or n";

send.println(question);

//system reads user input

answer1 = got.readLine();

if (answer1.equals("y")) {

send.println("Enter numbers separated by commas");

String datacurrent = got.readLine();


//split into strings separated by commas

String nums[]=datacurrent.split(',');

int len=nums.length;

double dataarray = new double[len];

//need to convert each string

for(int i=0;i<len;i++)

{ dataarray[i]=Double.parseDouble(nums[i]); }

// now you have a double array, which can be iterated over just as the for loop above


} //end of "y" if

if (answer1.equals("n")) {

send.println("Enter the path of your data file");

} //end of "n" if

} //end of main method

} //end of class computation