Java Practical No.13.pdf

  • Uploaded by: Meer Kukreja
  • 0
  • 0
  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Java Practical No.13.pdf as PDF for free.

More details

  • Words: 147
  • Pages: 4
13.1] Write a program to display array element using for-each loop.

class arr { public static void main(String args[]) { int[] array={1,2,3,4}; for(int a: array) { System.out.println(a); } } } Output:

13.2] Write a program to implement multidimensional array. import java.util.*; class mda { public static void main(String args[]) { int [][] a =new int[3][3]; int [][] b =new int[3][3]; int [][] c =new int[3][3]; int i=0,j=0;

Scanner s = new Scanner(System.in);

System.out.println("Enter your first matrix :" ); for(i=0;i<3;i++) { for(j=0;j<3;j++) {

a[i][j] = s.nextInt();

} }

System.out.println("Enter your second matrix :"); for(i=0;i<3;i++) { for(j=0;j<3;j++) {

b[i][j] = s.nextInt(); } }

System.out.println("Matrix 1: "); for(i=0;i<3;i++) { for(j=0;j<3;j++) {

System.out.print(a[i][j]+" ");

} System.out.println(" "); }

System.out.println("Matrix 2: "); for(i=0;i<3;i++) { for(j=0;j<3;j++) {

System.out.print(b[i][j]+" ");

} System.out.println(" "); }

System.out.println("Addition of matrix :"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { c[i][j] = a[i][j]+b[i][j]; System.out.print(c[i][j]+" ");

} System.out.println(" "); } } }

Output:

Related Documents


More Documents from "Meer Kukreja"