Question
I have tried a few routes with the Math_Results.csv and the results still will not populate in Excel. Any idea what can be the issue.
I have tried a few routes with the "Math_Results.csv" and the results still will not populate in Excel. Any idea what can be the issue. Was I supposed to create the folder under myjava or on excel?
import java.io.File;
import java.util.Scanner;
import java.io.FileWriter;
public class MathOP5 {
public static void main(String[] args)
{
Scanner in = new Scanner(System.in); // Scanner object
File file = new File("Math_Results.csv"); //Referal to Math_Results.csv
System.out.print("name?: "); // Scan users name
String name = in.nextLine();
System.out.println("Hello \"" + name + "\"");
System.out.print("Do you want to save the results (Y/N)? "); // Ask if results should be saved
String saveResult = in.nextLine();
System.out.print("numbers to average? "); // Numbers to average
int n = in.nextInt();
double average = 0;
System.out.print("Input " + n + " numbers: ");
String expression = ""; // If yes is selected, an expression will be shown
for(int i = 0; i < n; ++i)
{
double temp = in.nextDouble(); // User inmput n will be combined in average
average += temp;
if(saveResult.equals("Y")){ // Do you want to save results ?
if(i expression = expression+temp+" + "; else if(i==n-1) // Is this the last number entered? expression = expression+temp+" = "+average; } } // save results in csv file Y/N if(saveResult.equals("Y")){ try{ FileWriter myWriter = new FileWriter(file); myWriter.write(expression); myWriter.close(); } catch(Exception e){ System.out.println("Error"); } } average /= n; // Calculate average System.out.printf("The average is %.2f ", average); // Does the user want to review the results // If yes, then open the file and read the content System.out.print(" Do you want to review the results (Y/N)? "); String reviewResults = in.nextLine(); reviewResults = in.nextLine(); if(reviewResults.equals("Y")){ try{ Scanner sc = new Scanner(file); System.out.println("Results form Math_Results.csv"); while (sc.hasNextLine()){ System.out.println(sc.nextLine()); } } catch(Exception e){ System.out.println("Error"); } } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started