QuestionQuestion

Write a program to read three integers N, L, U from the input filename “input8.txt”. Note that the input file may contain comments before the actual numbers N, L and U. Assumed that L < U. Create a matrix of size N by N filled with random integers in the range [L, U]. Imagine that in this square matrix we will have 2 diagonals as follow
1
2
3
43

Write the following methods to
+ Symmetrically swap number in regions 1 and 2
+ Symmetrically swap number in regions 2 and 3
Output the resulted matrix to files “output8_01.txt” and “output8_02.txt”

Example
input8.txt
// This is the comment, your program should skip this line
// and also this line
4 5 30
Original matrix is
5 6 7 8
10 11 12 13
15 16 17 18
20 21 22 23
output8_01.txt
5 10 15 20
6 11 16 21
7 12 17 22
8 13 18 23
output8_02.txt
23 18 13 8
22 17 12 7
21 16 11 6
20 15 10 5

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.InputMismatchException;
import java.util.Scanner;


public class Solution {

public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException
{
Scanner fileIn = new Scanner(new File("input8.txt"));
PrintWriter writer1 = new PrintWriter("output8_01.txt", "UTF-8");
PrintWriter writer2 = new PrintWriter("output8_02.txt", "UTF-8");
int N, L, U;
String line;
int[][] matrix, matrix1, matrix2;
while(true)
{
try
{
N = fileIn.nextInt();
break;
}catch(InputMismatchException e){
fileIn.next();
continue;
}
}
L = fileIn.nextInt();
U = fileIn.nextInt();

matrix = new int[N][N];
for(int i = 0; i < N; i++)
for(int j = 0; j < N; j++)
matrix[i][j] = (int)(Math.random() * (L-U) + U);

System.out.println("Original matrix is: ");
for(int i = 0; i < N; i++)
{
for(int j = 0; j < N; j++)
System.out.print(matrix[i][j] + " ");
System.out.println();
}
matrix1 = matrixMod1(matrix);
System.out.println("First modified matrix is: ");
for(int i = 0; i < N; i++)
{...
$13.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats