I think you are creating an array of wrong bounds- instead of int [][] list=new int [2][mo] there should be int [][] list=new int [mo][2]; ,because for every module you have marks of first and second assignment, am I right?
Top answer 1 of 2
1
I think you are creating an array of wrong bounds- instead of int [][] list=new int [2][mo] there should be int [][] list=new int [mo][2]; ,because for every module you have marks of first and second assignment, am I right?
2 of 2
0
You can try this way
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner Sc = new Scanner(System.in);
int mo, i, j, a;
System.out.println(" how many modules you have in this semester ?");
mo = Sc.nextInt();
// creat the Array
int[] tab = new int[mo];
for (a = 0; a < mo; a++) {
System.out.println(" Enter the module name : " + (a + 1));
tab[a] = Sc.nextInt();
}
int[][] list = new int[2][mo];
for (i = 0; i < 2; i++) {
for (j = 0; j < mo; j++) {
System.out.println(" Enter the marks of the " +
(i + 1) + " Assignment : " + (i + 1) + "," + j);
list[i][j] = Sc.nextInt();
}
}
}
}
GitHub
gist.github.com βΊ eMahtab βΊ 297419cb805fe93346c0
Java program to take 2D array as input from user. Β· GitHub
June 11, 2019 - import java.util.Scanner; public class Multidimensional_Arrays { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int flates[][] = new int[2][3]; System.out.println("Enter array elements = "); for (int i = 0; i < flates.length; i++) { for (int j = 0; j <= flates.length; j++) { flates[i][j] = sc.nextInt(); System.out.print(flates[i][j] + " "); } } System.out.println(); //reverse System.out.println("Reverse of Multi-dimensional Array"); for (int i = flates.length - 1; i >= 0; i--) { for (int j = flates.length; j >= 0; j--) { System.out.print(flates[i][j] + " "); } } } }
Videos
11:02
Take User Defined Input in 2-Dimensional Array using JAVA ...
How To Get Array Input From A User In Java Using Scanner - YouTube
Passing Two Dimensional Arrays to Methods
05:15
Two Dimensional Array Example in Java - YouTube
04:15
Two dimension array using Scanner - YouTube
09:40
User input in arrays using Scanner class - Hindi - YouTube
IncludeHelp
includehelp.com βΊ java-programs βΊ read-and-print-a-two-dimensional-array.aspx
Java program to read and print a two dimensional array
December 23, 2023 - System.out.print("Enter row for ... scan.nextInt(); // enter array elements. System.out.println("Enter " + (row * col) + " Array Elements : "); for (i = 0; i < row; i++) { for (j = 0; j < col; j++) { arr[i][j] = scan.nextInt(); } } // the 2D array is here....
GeeksforGeeks
geeksforgeeks.org βΊ java βΊ multidimensional-arrays-in-java
Java Multi-Dimensional Arrays - GeeksforGeeks
Then print the multi-dimensional array and close the scanner object. Example: Java program to demonstrate how to create Two Dimensional Array with User input.
Published Β May 4, 2026
YouTube
youtube.com βΊ coding wallah sir
Two Dimensional Array in Java Using Scanner | Initialize Two Dimensional Array in Java - YouTube
Hi in this video we will learn about How to take user input in Two-Dimensional Array in Java Using Scanner ββββββββββββββββββββββππΌββοΈHello All Kaise Ho Sa...
Published Β March 25, 2021 Views Β 1K
Tutorjoes
tutorjoes.in βΊ Java_example_programs βΊ read_and_print_a_two_dimensional_array_in_java
Write a program to Read and print a Two Dimensional array
import java.util.Scanner; public class Read_Print { public static void main(String args[]) { Scanner input = new Scanner(System.in); int a[][] = new int[100][100]; int row, col, i, j; System.out.print("Enter Number of Rows : "); row = input.nextInt(); System.out.print("Enter Number of Columns : "); col = input.nextInt(); for (i = 0; i < row; i++) { for (j = 0; j < col; j++) { System.out.printf("Enter Array Elements a[%d][%d] :",i,j); a[i][j] = input.nextInt(); } } System.out.println("Display 2D Array Element is : "); for (i = 0; i < row; i++) { for (j = 0; j < col; j++) { System.out.print(a[i][j] + " "); } System.out.println(); } } }
Wyzant
wyzant.com βΊ resources βΊ ask an expert
Sort a double dimensional array in java using scanner class. | Wyzant Ask An Expert
April 8, 2021 - if you already know the size of original 2D matrix, create a 1D array first, then use Scanner to input the matrix from console line by line, and store the value into 1D array. once input finished, use Arrays.sort(array) to sort the 1D array, then print it out per 2D format. if the size of original ...
Kosbie
kosbie.net βΊ cmu βΊ fall-08 βΊ 15-100 βΊ handouts βΊ notes-two-dimensional-arrays.html
Two-Dimensional Arrays
import java.util.*; class MyCode { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter # of rows: "); int rows = scanner.nextInt(); System.out.print("Enter # of cols: "); int cols = scanner.nextInt(); int[][] a = new int[rows][cols]; System.out.print("Enter " + rows + "x" + cols + "=" + (rows*cols) + " integers: "); for (int i=0; i<rows; i++) for (int j=0; j<cols; j++) a[i][j] = scanner.nextInt(); System.out.println("Here are those " + (rows*cols) +" integers in a " + rows + "x" + cols + " 2d-array:"); System.out.println(Arrays.deepToStrin
BeginnersBook
beginnersbook.com βΊ 2024 βΊ 06 βΊ how-to-take-array-input-in-java
How to take array input in Java
The approach is similar here, however in order to take 2D array inputs, we need to use the nested for loop. Also, we need additional row and column inputs from user. import java.util.Scanner; public class TwoDArrayInputExample { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter the number of rows: "); int rows = scanner.nextInt(); System.out.print("Enter the number of columns: "); int cols = scanner.nextInt(); int[][] array = new int[rows][cols]; System.out.println("Enter the elements of the array:"); for (int i = 0; i < rows; i++) { for
Top answer 1 of 4
4
String result="";//this variable for the last line which print the result
for (int i = 0; i < row; i++) {
result=result+"Data Array "+i+" :";
for (int j = 0; j < column; j++) {
System.out.println("Row [" + i + "]: Column " + j + " :");
matrix[i][j] = sc.nextInt();
result=result+matrix[i][j]+", ";
}
}
System.out.println(result);////for the final result
2 of 4
0
for(int j = 0; j < column; j++) {
System.out.println("Row ["+i+"]: Column "+j+" :");
matrix[i][j] = sc.nextInt(); //Storing input value here
System.out.println(matrix[i][j]);//Output the input value
}
Stack Overflow
stackoverflow.com βΊ questions βΊ 52909506 βΊ initialized-a-two-dimensional-array-using-scanner-when-trying-to-display-two-di
java - Initialized a Two Dimensional Array using Scanner. When trying to display two dimensional array, array values are all nulled - Stack Overflow
public class TwoDimensionalArrays { public static void main(String[] args) { displayTwoDimensionalArray(firstTwoDimensionalArray); int secondTwoDimensionalArray[][] = new int[4][3]; initTwoDimensionalArray(secondTwoDimensionalArray); displayTwoDimensionalArray(secondTwoDimensionalArray); } public static void displayTwoDimensionalArray(int x[][]) { for(int row = 0; row < x.length; row++) { for(int col = 0; col < x[row].length; col++) { System.out.print(x[row][col] + "\t"); } System.out.println(); } System.out.println(); } public static void initTwoDimensionalArray(int x[][]) { Scanner scan = ne
Blogger
javarevisited.blogspot.com βΊ 2016 βΊ 07 βΊ how-to-take-array-input-in-java-using-Scanner-Example.html
How to take array input from command line in Java ? Scanner Example
April 2, 2025 - Now, let's see the output of this program to understand how to take array as input from command line in Java: Output Please enter length of String array 3 Please enter array elements Java C++ Ruby The String array input from user is : [Java, C++, Ruby] Please enter number of rows and columns of 2D array 2 3 Please enter array elements row by row 1 2 3 4 5 6 The 2d int array input from user is : [[1, 2, 3], [4, 5, 6]] You can see that we have successfully taken array input from the user, both String and integer array, and both one and a two-dimensional array. Don't forget to close the Scanner once you have done to prevent resource leaks in Java, you can also see these Java programming courses to learn more about why you should close readers and stream once you are done using them.
Chegg
chegg.com βΊ engineering βΊ computer science βΊ computer science questions and answers βΊ 2 dimensional arrays a two dimensional array is an array of arrays.2 dimensional arrays a two dimensional array is an array of arrays. datatype [ ] [ arrayname = new int [ ] [ ]; 2d array datatype [ ] [ [ ] arrayname = new int [ ] [] [ ]; 3d array 2 dimensional arrays two dimensional array is an array of arrays. declaring a two dimensional array: datatype
Solved 2 Dimensional Arrays A two dimensional array is an | Chegg.com
February 5, 2023 - ... //import java scanner class import java.util.Scanner; class Test{ public static void main(String[] args) { //demonstrates two dimensional arrays int [][] twoD = new int [2][2]; int i, j = 0 ; Scanner input = new Scanner(System.in); //take input into the array for (i= 0 ; i< 2 ; i++) for ...