Results 1 to 2 of 2
  1. #1
    peek_a_boo is offline Member
    Join Date
    Dec 2011
    Rep Power

    Default Creating 2D array from all user input


    I'm working on a project and I need to write a program that asks the user for the 2 dimensions, and then the program asks the user to enter all the elements by row and column which I've successfully done but I can't figure out how to print out the finished matrix. Here's what I have so far:

    import java.util.Scanner;

    public class Num_1 {

    public static void main (String[] args) {

    Scanner scanner = new Scanner (;

    int rows;

    int columns;

    System.out.println("Enter number of rows: ");

    rows = scanner.nextInt();

    System.out.println ("Now enter the number of columns: ");

    columns = scanner.nextInt();

    int [][] matrix = new int [rows] [columns];

    for (int i = 0; i < rows; i++) {

    for (int j = 0; j < columns; j++) {

    System.out.println("Enter the number for row " + i + " and column " + j + " : ");

    matrix [i][j] = scanner.nextInt();





  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power

    Default Re: Creating 2D array from all user input

    how to print out the finished matrix.
    You could use a nested loop with the outer loop iterating through the rows and the inner loop thru the columns.
    Use the print method for each element on a row and use println to go to the next row when a row is finished.

Similar Threads

  1. Creating an object based on user input parameters
    By monkeyhead in forum New To Java
    Replies: 5
    Last Post: 11-15-2011, 12:59 AM
  2. Creating a number of objects based on user input.
    By Kevinius in forum New To Java
    Replies: 21
    Last Post: 04-03-2011, 09:53 AM
  3. Replies: 2
    Last Post: 01-13-2011, 06:43 AM
  4. Creating a Table with user input
    By JonniBravo in forum Eclipse
    Replies: 1
    Last Post: 09-08-2010, 01:50 PM
  5. Creating a dialog to input user/password
    By prfalco in forum New To Java
    Replies: 4
    Last Post: 02-18-2008, 08:03 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts