Implement the following flow chart in Java You should have o

Implement the following flow chart in Java. You should have one Java file in the project called \"Problem 1.java\". The class should be called \"Problem1\". Generate Data Method

Solution

// Project1.java
import java.util.*;
import java.io.FileWriter;

public class Project1
{
public static void generateData(int[] array, int k)
{
     int n = 0;
  
     while (n < k)
     {
        // add n*100 to arra
        array[n] = n*100;

        // increment n
        n = n + 1;
     }
}

public static void main(String[] argv) throws Exception
{
    // scanner object (called input).
      Scanner input = new Scanner(System.in);
      FileWriter fw = new FileWriter(\"output.txt\");

      System.out.print(\"Enter integer k: \");
      int k = input.nextInt();
    
      // array of k integers
      int array[]=new int[k];//declaration and instantiation

      generateData(array, k);

      // write array data to file
      for (int i = 0; i < array.length; i++)
      {
        fw.write(array[i] + \"\\t\");
      }
      fw.close();
}
}

/*
output:
Enter integer k: 10

output.txt
0 100 200 300 400 500 600 700 800 900

*/

 Implement the following flow chart in Java. You should have one Java file in the project called \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site