this file is named HW3.Java can someone run it through a GNU compiler and please show me the outputs the input arguements are  $ java HW3 p1 p1.txt 6  import java.io.FileWriter; import java.io.IOException; public class HW3 { public static void main(String[] args) throws IOException { // 0th argument contains the name of algorithm String algo = args[0]; // 1st argument contains the name of file // Make a new file FileWriter fw = new FileWriter(args[1]); if (algo.equals("p1")) { // 2nd argument comes in the form of string. // convert it to intger and run a loop for (int i = 1; i <= Integer.parseInt(args[2]); i++) { double[] x = new double[(int) Math.pow(10, i)]; // use start and end for recording time long start = System.currentTimeMillis(); prefixAverage1(x); long end = System.currentTimeMillis(); double totalTime = Math.log10(end - start); fw.write(String.valueOf(totalTime)); String newLine = System.getProperty("line.separator"); fw.write(newLine); } } else if (algo.equals("p2")) { for (int i = 1; i <= Integer.parseInt(args[2]); i++) { double[] x = new double[(int) Math.pow(10, i)]; long start = System.currentTimeMillis(); prefixAverage2(x); long end = System.currentTimeMillis(); double totalTime = Math.log10(end - start); fw.write(String.valueOf(totalTime)); String newLine = System.getProperty("line.separator"); fw.write(newLine); } } else if (algo.equals("e1")) { for (int i = 1; i <= Integer.parseInt(args[2]); i++) { int[] x = new int[(int) Math.pow(10, i)]; long start = System.currentTimeMillis(); example1(x); long end = System.currentTimeMillis(); double totalTime = Math.log10(end - start); fw.write(String.valueOf(totalTime)); String newLine = System.getProperty("line.separator"); fw.write(newLine); } } else if (algo.equals("e2")) { for (int i = 1; i <= Integer.parseInt(args[2]); i++) { int[] x = new int[(int) Math.pow(10, i)]; long start = System.currentTimeMillis(); example2(x); long end = System.currentTimeMillis(); double totalTime = Math.log10(end - start); fw.write(String.valueOf(totalTime)); String newLine = System.getProperty("line.separator"); fw.write(newLine); } } else if (algo.equals("e3")) { for (int i = 1; i <= Integer.parseInt(args[2]); i++) { int[] x = new int[(int) Math.pow(10, i)]; long start = System.currentTimeMillis(); example3(x); long end = System.currentTimeMillis(); double totalTime = Math.log10(end - start); fw.write(String.valueOf(totalTime)); String newLine = System.getProperty("line.separator"); fw.write(newLine); } } else if (algo.equals("e4")) { for (int i = 1; i <= Integer.parseInt(args[2]); i++) { int[] x = new int[(int) Math.pow(10, i)]; long start = System.currentTimeMillis(); example4(x); long end = System.currentTimeMillis(); double totalTime = Math.log10(end - start); fw.write(String.valueOf(totalTime)); String newLine = System.getProperty("line.separator"); fw.write(newLine); } } else if (algo.equals("e5")) { for (int i = 1; i <= Integer.parseInt(args[2]); i++) { int[] x = new int[(int) Math.pow(10, i)]; long start = System.currentTimeMillis(); // You can take a new array here, I am just running it for x here example5(x, x); long end = System.currentTimeMillis(); double totalTime = Math.log10(end - start); fw.write(String.valueOf(totalTime)); String newLine = System.getProperty("line.separator"); fw.write(newLine); } } fw.close(); } public static double[] prefixAverage1(double[] x) { int n = x.length; double[] a = new double[n]; for (int j = 0; j < n; j++) { double total = 0; for (int i = 0; i <= j; i++) { total += x[i]; a[j] = total / (j + 1); } } return a; } public static double[] prefixAverage2(double[] x) { int n = x.length; double[] a = new double[n]; double total = 0; for (int j = 0; j < n; j++) { total += x[j]; a[j] = total / (j + 1); } return a; } public static int example1(int[] arr) { int n = arr.length, total = 0; for (int j = 0; j < n; j++) total += arr[j]; return total; } public static int example2(int[] arr) { int n = arr.length, total = 0; for (int j = 0; j < n; j += 2) total += arr[j]; return total; } public static int example3(int[] arr) { int n = arr.length, total = 0; for (int j = 0; j < n; j++) for (int k = 0; k <= j; k++) total += arr[j]; return total; } public static int example4(int[] arr) { int n = arr.length, prefix = 0, total = 0; for (int j = 0; j < n; j++) { prefix += arr[j]; total += prefix; } return total; } public static int example5(int[] first, int[] second) { int n = first.length, count = 0; for (int i = 0; i < n; i++) { int total = 0; for (int j = 0; j < n; j++) for (int k = 0; k <= j; k++) total += first[k]; if (second[i] == total) count++; } return count; } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

this file is named HW3.Java can someone run it through a GNU compiler and please show me the outputs

the input arguements are 

$ java HW3 p1 p1.txt 6 

import java.io.FileWriter;
import java.io.IOException;
public class HW3 {
public static void main(String[] args) throws IOException {
// 0th argument contains the name of algorithm
String algo = args[0];
// 1st argument contains the name of file
// Make a new file
FileWriter fw = new FileWriter(args[1]);
if (algo.equals("p1")) {
// 2nd argument comes in the form of string.
// convert it to intger and run a loop
for (int i = 1; i <= Integer.parseInt(args[2]); i++) {
double[] x = new double[(int) Math.pow(10, i)];
// use start and end for recording time
long start = System.currentTimeMillis();
prefixAverage1(x);
long end = System.currentTimeMillis();
double totalTime = Math.log10(end - start);
fw.write(String.valueOf(totalTime));
String newLine = System.getProperty("line.separator");
fw.write(newLine);
}
} else if (algo.equals("p2")) {
for (int i = 1; i <= Integer.parseInt(args[2]); i++) {
double[] x = new double[(int) Math.pow(10, i)];
long start = System.currentTimeMillis();
prefixAverage2(x);
long end = System.currentTimeMillis();
double totalTime = Math.log10(end - start);
fw.write(String.valueOf(totalTime));
String newLine = System.getProperty("line.separator");
fw.write(newLine);
}
} else if (algo.equals("e1")) {
for (int i = 1; i <= Integer.parseInt(args[2]); i++) {
int[] x = new int[(int) Math.pow(10, i)];
long start = System.currentTimeMillis();
example1(x);
long end = System.currentTimeMillis();
double totalTime = Math.log10(end - start);
fw.write(String.valueOf(totalTime));
String newLine = System.getProperty("line.separator");
fw.write(newLine);
}
} else if (algo.equals("e2")) {
for (int i = 1; i <= Integer.parseInt(args[2]); i++) {
int[] x = new int[(int) Math.pow(10, i)];
long start = System.currentTimeMillis();
example2(x);
long end = System.currentTimeMillis();
double totalTime = Math.log10(end - start);
fw.write(String.valueOf(totalTime));
String newLine = System.getProperty("line.separator");
fw.write(newLine);
}
} else if (algo.equals("e3")) {
for (int i = 1; i <= Integer.parseInt(args[2]); i++) {
int[] x = new int[(int) Math.pow(10, i)];
long start = System.currentTimeMillis();
example3(x);
long end = System.currentTimeMillis();
double totalTime = Math.log10(end - start);
fw.write(String.valueOf(totalTime));
String newLine = System.getProperty("line.separator");
fw.write(newLine);
}
} else if (algo.equals("e4")) {
for (int i = 1; i <= Integer.parseInt(args[2]); i++) {
int[] x = new int[(int) Math.pow(10, i)];
long start = System.currentTimeMillis();
example4(x);
long end = System.currentTimeMillis();
double totalTime = Math.log10(end - start);
fw.write(String.valueOf(totalTime));
String newLine = System.getProperty("line.separator");
fw.write(newLine);
}
} else if (algo.equals("e5")) {
for (int i = 1; i <= Integer.parseInt(args[2]); i++) {
int[] x = new int[(int) Math.pow(10, i)];
long start = System.currentTimeMillis();
// You can take a new array here, I am just running it for x here
example5(x, x);
long end = System.currentTimeMillis();
double totalTime = Math.log10(end - start);
fw.write(String.valueOf(totalTime));
String newLine = System.getProperty("line.separator");
fw.write(newLine);
}
}
fw.close();
}
public static double[] prefixAverage1(double[] x) {
int n = x.length;
double[] a = new double[n];
for (int j = 0; j < n; j++) {
double total = 0;
for (int i = 0; i <= j; i++) {
total += x[i];
a[j] = total / (j + 1);
}
}
return a;
}
public static double[] prefixAverage2(double[] x) {
int n = x.length;
double[] a = new double[n];
double total = 0;
for (int j = 0; j < n; j++) {
total += x[j];
a[j] = total / (j + 1);
}
return a;
}
public static int example1(int[] arr) {
int n = arr.length, total = 0;
for (int j = 0; j < n; j++)
total += arr[j];
return total;
}
public static int example2(int[] arr) {
int n = arr.length, total = 0;
for (int j = 0; j < n; j += 2)
total += arr[j];
return total;
}
public static int example3(int[] arr) {
int n = arr.length, total = 0;
for (int j = 0; j < n; j++)
for (int k = 0; k <= j; k++)
total += arr[j];
return total;
}
public static int example4(int[] arr) {
int n = arr.length, prefix = 0, total = 0;
for (int j = 0; j < n; j++) {
prefix += arr[j];
total += prefix;
}
return total;
}
public static int example5(int[] first, int[] second) {
int n = first.length, count = 0;
for (int i = 0; i < n; i++) {
int total = 0;
for (int j = 0; j < n; j++)
for (int k = 0; k <= j; k++)
total += first[k];
if (second[i] == total) count++;
}
return count;
}
}

Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Constants and Variables
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education