Wednesday, 13 May 2020

Print all the String elements using DDA

Write a program to input and store String elements in a double dimensional array of size  3 x 4  and Print all the String elements.

import java.util.*;

class  DD
{
    public static void main(String arg[])
    {
        String[][]  nm = new String[3][4];
                 
        Scanner sk = new Scanner(System.in); 
    
        System.out.println("Enter the names  ");
        
        for(int i=0 ; i<3 ; i++)
        {
            for(int j=0 ; j<4 ; j++)
            {
                nm[i][j] = sk.nextLine();
            }
        }
        
        System.out.println("The output is : ") ; 
        
        for(int i=0 ; i<3 ; i++)
        {
            for(int j=0 ; j<4 ; j++)
            {
               System.out.print(nm[i][j] + "  ") ;  
            }
            System.out.println() ; 
        }          
    
    }
}

=================================================

Subscribe and Share my Blog and YouTube channel 

Blog : www.definecompute.blogspot.com

YouTube  :  SK Skill India 

================================================





Find the sum of diagonal elements in Java

Write a program to input and store integer elements in a double dimensional array of size  3 x 3  and find the sum of diagonal elements. 

import java.util.*;

class DDA
{
    public static void main(String arg[])
    {
        int[][] num = new int[3][3];
       
        int x = 0 ;
       
        Scanner sk = new Scanner(System.in);
   
        System.out.println("Enter all the values ");
       
        for(int i=0 ; i<3 ; i++)
        {
            for(int j=0 ; j<3 ; j++)
            {
                num[i][j] = sk.nextInt();
            }
        }
       
        x = num[0][0] + num[1][1] + num[2][2] + num[0][2] + num[2][0] ; 
       
        System.out.println("The sum of the diagonal elements is : " +x) ;
   
    }
}

====================================================

Search my YouTube channel   :    SK Skill India 

====================================================








Find the sum of all the elements in DDA


Write a program to input and store integer elements in a double dimensional array of size  3 x 4  and find the sum of all the elements.

import java.util.*;

class DDA
{
    public static void main(String arg[])
    {
        int[][] num = new int[3][4];
       
        int x = 0 ;
       
        Scanner sk = new Scanner(System.in);
   
        System.out.println("Enter all the values ");
       
        for(int i=0 ; i<3 ; i++)
        {
            for(int j=0 ; j<4 ; j++)
            {
                num[i][j] = sk.nextInt();
            }
        }
       
        for(int i=0 ; i<3 ; i++)
        {
            for(int j=0 ; j<4 ; j++)
            {
                x = x + num[i][j] ;
            }
        }   
       
        System.out.println("The sum of all the elements is : " +x) ;
   
    }
}



Tuesday, 12 May 2020

Print all the integer elements in DDA

Write a program to input and store integer elements in a double dimensional array of size  3 x 4  and Print all the integer elements.


                                               // User Defined
import java.util.*;
class  DDA
{
    public static void main(String args[])
    {
        int[][] num = new int[3][4];
        Scanner sk=new Scanner(System.in) ;         
        System.out.println("Enter ur Value :") ;   
      
        // This loop is used to store the values in the array index 

        for(int i=0 ; i<3 ; i++)                     //Row
        {
            for(int j=0 ; j<4 ; j++)                // Column
            {
                num[i][j] = sk.nextInt();
            }         
        }     
 
         System.out.println(" The output is  :") ;        

        for(int i=0 ; i<3 ; i++)
        {
            for(int j=0 ; j<4 ; j++)
            {
                System.out.print(num[i][j] + "  ");      // Use print instead of println
            }                 //use double quotation for space between each number   

            System.out.println();             // This println() is use to change of row
        }           
    }
}


======================================================

Subscribe my YouTube channel  :   SK Skill India 

======================================================










Basic concept of Double Dimensional Array


Double Dimensional arrays is consists of two subscripts : one for the row and other for the column. 
The first subscript is always the row subscript and second is column subscript.   

class  Array2D
{
    public static void main(String args[])
    { 

        int[][] A = new int[2][3] ;
        A[0][1] = 11 ;
        A[0][1] = 22 ;
        A[0][2] = 33 ;
        A[1][0] = 44 ;
        A[1][1] = 55 ;
        A[1][2] = 66 ;           
        System.out.println(" The value is " + A[0][2]) ;
        System.out.println(" The value is " + A[1][1]) ;
    }
}                     
==========================================================

// Two Dimensional arrays is consists of two subscripts : one for the row and other for the column. 

class  DDA
{
    public static void main(String args[])
    {
        int[][] A = {{10,20,30} , {40,50,60}};         
        System.out.println(" The value is " + A[0][2]) ;
        System.out.println(" The value is " + A[1][1]) ;
    }
} 

======================================================

Subscribe my YouTube channel  :  SK Skill India 

=======================================================