Skip to main content

Let's CODE IT...Boundary elements in a matrix

If your're looking for easy method to print boundary elements,then you are at the right place.....


****************************
HERE IS THE CODE:
****************************

import java.util.*;
class Only_Boundary_Elements
{
    public static void main()
    {
        Scanner sc=new Scanner(System.in);
        int i,j,Temp,n=0;
        System.out.println("Enter  the Number of Rows");
        int r=sc.nextInt();
        System.out.println("Enter  the Number of Columns");
        int c=sc.nextInt();
        int arr[][]=new int[r][c];
        System.out.println("Enter the Elements of Matrix");
        for(i=0;i<r;i++)
        {
            for(j=0;j<c;j++)
            {
                arr[i][j]=sc.nextInt();
            }
        }
        System.out.println("Input Matrix Is :-");
        for(i=0;i<r;i++)
        {
            for(j=0;j<c;j++)
            { 
                System.out.print(arr[i][j]+" ");
            }
            System.out.println(" ");
        }
        System.out.println("OUTPUT:\nORIGINAL MATRIX");
        for(int k=0;k<r;k++)
        {
            for(int l=0;l<c;l++)
            {
                if(k==0 || k==r-1)
                {
                 System.out.print(arr[k][l]+"\t");
                }
                else if(l==0 || l==c-1)
                {
                    System.out.print(arr[k][l]+"\t");
                }
                else
                System.out.print(" \t");
            }
            System.out.println("");
        }
    }
}

****************************************************************************

OUTPUT:

------------









Comments

Popular posts from this blog

ISC Computer Science-2020 Paper 2(Theory) Q7. Solved

Computer Science Paper -(ISC Programs 2020) Write a program in JAVA to to find the date and the month from a given day number for a particular year. For e.g.  Year: 2020 Day: 64 March 4, 2020     ----------------------------------------------------------------------      import java.util.*; public class Q_7 {     public static void main(String args[])     {         Scanner sc=new Scanner(System.in);         System.out.println("Year : ");         int i,f,s;         int year=sc.nextInt();         System.out.println("Day : ");         int d=sc.nextInt();         int a[]={31,28,31,30,31,30,31,31,30,31,30,31};         String b[]={"January","February","March","April","May","June","July","August","September","October","November","December"}; ...

You got latest news updates here.......

Jeep stranded in a  water becomes a Social Media Sensation The vehicle, which the police in Myrtle shore, S.C., found abandoned as Hurricane Dorian loomed, grew into a popular meme. As he was turning, Mr. Farrar got stuck in a ditch in the sand and left the vehicle in search of help, but all of the towing companies he called said they couldn’t get to the vehicle before the hurricane was expected to strike. Someone noticed the abandoned vehicle on the beach, and called the police. Officers were sent around 7 a.m., according to a police report, but with the hurricane nearly upon them, they determined it was too dangerous for a tow truck to remove the Jeep. Before leaving, one officer attached a buoy to the bumper so the vehicle could be located later.

News

NEWS News  is  information  about current events. This may be provided through many different  media :  word of mouth ,  printing ,  postal systems ,  broadcasting ,  electronic communication , or through the  testimony  of observers and  witnesses  to events. Common topics for news reports include war, government, politics, education, health, the environment, economy, business, fashion, and entertainment, as well as athletic events, quirky or unusual events.  Government  proclamations, concerning royal ceremonies, laws, taxes, public health, and criminals, have been dubbed news since ancient times. Humans exhibit a nearly universal desire to learn and share news, which they satisfy by talking to each other and sharing information. Technological and social developments, often driven by government communication and espionage networks, have increased the speed with which news can spread, as well as influenc...