JAVA   25
ASP
Guest on 13th March 2023 01:22:06 PM


  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class ASP {
  5.    public static void main(String[] args) throws IOException {
  6.      System.out.println("This program will generate an Assignment instance\n");
  7.          System.out.print("\nEnter the destination file name-->");
  8.          String fileName = Tools.GetString();//input file name
  9.           try{
  10.           System.out.print("\nEnter directory name of destination file-->");
  11.            String dirName = Tools.GetString();
  12.            File outputfile = new File(dirName, fileName);
  13.             System.out.print("How many companies -->");
  14.                       int vertices = Tools.GetInt();
  15.                       int[][] Graph = new int[vertices][vertices];
  16.                       int n, m;
  17.                                          for ( n = 0; n < vertices; n++)
  18.                                                 for ( m = 0; m < vertices; m++){
  19.                                                     int k = 30 +(int)(99*Math.random()%75);
  20.                                                     Graph[n][m] = k;
  21.                                                          }//for loop
  22.         PrintWriter output = new  PrintWriter(new FileWriter(outputfile));
  23.                    for (n = 0; n < vertices; n++) {
  24.                                 for ( m = 0; m < vertices; m++)
  25.                 if (Graph[n][m] < 10)
  26.                  output.print("   " + Graph[n][m]);
  27.                 else if (Graph[n][m] < 100)
  28.                  output.print("  " + Graph[n][m]);
  29.                  else
  30.                   output.print(" " + Graph[n][m]);
  31.                    output.println();
  32.                              }
  33.                 output.close();
  34.                         }//try
  35.                         catch (IOException e)
  36.                                           {
  37.                                             System.err.println("Error opening file" +e);
  38.                                             return;
  39.             }
  40.                 }
  41.     }

Raw Paste

Login or Register to edit or fork this paste. It's free.