Array-promo
Matrix-promo

Question

Program to display the odd number in the matrix

Matrix  = [9, 8, 7]
          [6, 5, 4]
          [3, 2, 1]

ODD NUMBER IN MATRIX
9     7
   5
3     1

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

import java.util.Scanner;
public class OddNumberInMatrix
{
    public static void main(String[] args)
    {
        int row=0, col=0,i=0,j=0;
        int a[][];


        Scanner sc=new Scanner(System.in);
        System.out.println("ENTER THE ROW OF MATRIX");
        row=sc.nextInt();
        System.out.println("ENTER THE COLUMN OF MATRIX");
        col=sc.nextInt();

        a=new int[row][col];
        System.out.println("ENTER THE ELEMENTS IN MATRIX");
        for(i=0;i< row;i++)
        {
            for(j=0;j< col;j++)
            {
                a[i][j]=sc.nextInt();
            }
        }



        /*if a[i][j]%2!=0 then print number present in  array at that position else print spaces */
        System.out.println("ODD NUMBER IN MATRIX");

        for(i=0;i< row;i++)
        {
            for(j=0;j< col;j++)
            {
                if(a[i][j]%2!=0)
                {
                    System.out.print(a[i][j]+" ");

                }
                else
                {
                    System.out.print("  ");
                }

            }
            System.out.println();
        }



    }
}

Coding Store

Sale

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹250.Current price is: ₹150.
Sale

Original price was: ₹350.Current price is: ₹200.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale
Mastering Array

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹250.Current price is: ₹150.
Sale

Original price was: ₹350.Current price is: ₹200.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale
Mastering Array

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹250.Current price is: ₹150.
Sale

Original price was: ₹350.Current price is: ₹200.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale
Mastering Array

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹80.Current price is: ₹50.

Leave a Reply

Your email address will not be published. Required fields are marked *