Question

Write a java program that create a 2 dimensional array of type double of size 10...

Write a java program that create a 2 dimensional array of type double of size 10 by 10.

Fill the array with random numbers using a random number generator.

Print the array contents.

Write a java program that creates a file called data.txt that uses the PrintWriter class.

Write the numbers 1 to 42 into the file. Close the file. Attach both files.

Thank you in advance

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Random;

public class RandomMatric {

    public static void main(String[] args) {
        Random random = new Random();
        int[][] matrix = new int[10][10];
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                matrix[i][j] = random.nextInt(1000);
            }
        }
        // print array
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                System.out.print(matrix[i][j] + " ");
            }
            System.out.println();
        }
    }
}

import java.io.FileNotFoundException;
import java.io.PrintWriter;

public class WriteFile42 {

    public static void main(String[] args) throws FileNotFoundException {
        PrintWriter pw = new PrintWriter("data.txt");
        for (int i = 1; i <= 42; i++) {
            pw.println(i);
        }
        pw.close();
    }
}
Add a comment
Know the answer?
Add Answer to:
Write a java program that create a 2 dimensional array of type double of size 10...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT