KnowledgeBoat Logo
|

Computer Applications

Write a program Lower-left-half which takes a two dimensional array A, with size N rows and N columns as argument and prints the lower left-half.

                    2 3 1 5 0
                    7 1 5 3 1
e.g.,If A is        2 5 7 8 1
                    0 1 5 0 1
                    3 4 9 1 5

                    2
                    7 1
The output will be  2 5 7
                    0 1 5 0
                    3 4 9 1 5

Java

Java Arrays

7 Likes

Answer

import java.util.Scanner;

public class KboatLowerLeftHalf
{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        
        System.out.print("Enter size of 2D array :" );
        int n = in.nextInt();
        int A[][] = new int[n][n];
        
        System.out.println("Enter array elements : ");
        for(int i = 0; i < n; i++)  
        {   
            for(int j = 0; j < n; j++) 
            {
                A[i][j] = in.nextInt();
            }       
        } 
        
        System.out.println("Original array :" );
        for(int i = 0; i < n; i++)  
        {   
            for(int j = 0; j < n; j++) 
            {
                System.out.print(A[i][j] + " ");
            }
            System.out.println();          
        }  
        
        System.out.println("Lower Left Half array :" );
        
        for(int i = 0; i < n; i++)  
        {   
            for(int j = 0; j <= i; j++)
            {
                System.out.print(A[i][j] + " ");
            }
            
            System.out.println();          
        }  
        
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of Write a program Lower-left-half which takes a two dimensional array A, with size N rows and N columns as argument and prints the lower left-half. 2 3 1 5 0 7 1 5 3 1 e.g.,If A is 2 5 7 8 1 0 1 5 0 1 3 4 9 1 5 2 7 1 The output will be 2 5 7 0 1 5 0 3 4 9 1 5

Answered By

2 Likes


Related Questions