Java program: Read Matrix with Scanner nextInt() – Part 1

Опубликовано: 18 Март 2026
на канале: CodeWithBK
151
4

Java program: Read Matrix with Scanner nextInt() – Part 1

Welcome to CodeWithBK — your go-to hub for mastering Java programming.

In this video, you will learn how to read an integer matrix in Java using the Scanner class with the nextInt() method. This step-by-step tutorial is perfect for Java beginners who want to understand how to take matrix input from the user in a clean and simple way.

Input given is number of rows and number of columns for the matrix ( 2D Array ), followed by the elements of the matrix.

Example:
Input:
2
3
4 5 6
7 8 9
(The first two lines of input are the number of rows and numbers of columns for the 2D array.
Input is to read a 2D array of size 2x3, i.e. 2 rows and 3 column. )

This is Part 1 of 2.

What you’ll learn in this video:
Brief explanation of how a Scanner class works in Java
Use nextInt method of Scanner class to read integer input
How to declare and initialise a 2D integer array in Java
Using Scanner and nextInt() to read matrix values
reading the number of rows and columns and then reading the values into the matrix
Looping through rows and columns for user input
Printing the matrix in a readable format

By the end of this video, you will have a clear understanding of reading a matrix in Java using nextInt() — a skill that’s useful for many Java programming problems.

Perfect for:
B.Tech / BCA students
Beginners learning Java input methods
Coding interview prep
ICSE Class 10 Computer Applications students
ISC Computer Science Class 11 & Class 12 students
AP Computer Science students learning Java
Anyone wanting to understand Scanner in detail
Students preparing for Java programming exams
Java Practice program in 2D Arrays & Scanner

Programming Language: Java
Level: Beginner-friendly

Part 2 :    • Java program: Read Matrix with Scanner nex...  

Related Videos:
Array input of Strings :    • Java Program to Read an Array of Strings u...  
How does nextInt() work in a Scanner class:    • Java – Using nextInt() in Scanner  

Timestamps:
00:00 Introduction
01:05 Code template - main method
02:44 how does nextInt of Scanner class work
05:41 Java Code and explanation
07:45 dry run of the code
15:20 testing the Java code

🔔 Don’t forget to like, share, and subscribe to CodeWithBK for more such Java tutorials in simple language!

Stay connected:
Subscribe:    / @codewithbk  
Email: [email protected]
Discord:   / discord  

Coding mentor profile: https://www.codementor.io/@balkrishna...
For 1:1 sessions, reach out to me here : https://www.codementor.io/@balkrishna...

My YouTube channel where I teach in Hindi :    / @codewithbkhindi  

#JavaTutorial #JavaBeginners #CodeWithBK #JavaBeginners #JavaInterviewQuestions #JavaBasics #javatutorialforbeginners #javaprogrammingbasics #javaprogrammingforbeginners