Write a program to Read and print a Two Dimensional array


This is a Java program that calculates the number of days between two years. It prompts the user to enter a start year and an end year, and then it calculates the number of days in each year between the start and end years. The program consists of three methods:

  • The main method: This is the entry point for the program. It prompts the user to enter the start year and end year, and then it calls the num_of_Days method to calculate the number of days in each year between the start and end years. If the end year is greater than the start year, it prints the year and the number of days. Otherwise, it prints an error message.
  • The num_of_Days method: This method takes a year as a parameter and returns the number of days in that year. It calls the leap_Year method to check if the year is a leap year.
  • The leap_Year method: This method takes a year as a parameter and returns true if the year is a leap year, and false otherwise.

Overall, this program is a simple implementation of a common problem in programming - calculating the number of days between two dates. It uses basic Java syntax and concepts, such as methods, loops, conditionals, and user input.

Source Code

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();
		}
	}
}

Output

Enter Number of Rows : 2
Enter Number of Columns : 3
Enter Array Elements a[0][0] :1
Enter Array Elements a[0][1] :2
Enter Array Elements a[0][2] :3
Enter Array Elements a[1][0] :4
Enter Array Elements a[1][1] :5
Enter Array Elements a[1][2] :6
Display 2D Array Element is :
1  2  3
4  5  6

Example Programs