Java tutorial - Ignou MCA students

SHARE
SEM - 2     JAVA

SESSION1_EX1

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mcs025;

/**
 *
 * @author KETAN
 */
public class SESSION1_EX1 {
   
    public static void main(String args[])
    {
        int height=10,width=20,area;
        area=height * width;
        System.out.println("The area of ranctangle is " +area);
       
    }
   
}
    
=====================================================================                    
session1_ex4

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mcs025;

/**
 *
 * @author KETAN
 */
public class session1_ex4 {
   
    public static void main(String args[])
    {
        int marks=616,sub=7,avg;
        avg=marks / sub;
        System.out.println( "The average marks is "+avg);
       
    }
   
}
===============================================================
session2_ex1

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mcs025;

/**
 *
 * @author KETAN
 */
import java.util.*;
public class session2_ex1 {
   
    public static void main(String args[])
    {
        int a[][]=new  int [3][3];
          int b[][]=new  int [3][4];
            int c[][]=new  int [3][4];
            int i,j,k;
            Scanner p=new Scanner(System.in);
           
          System.out.println("Enter first matrix");
              for(i=0;i<=2;i++)
          {
              for(j=0;j<=2;j++)
              {
                  a[i][j]=p.nextInt();
              }
          }
              System.out.println("Enter second matrix");
              for(i=0;i<=2;i++)
          {
              for(j=0;j<=3;j++)
              {
                  b[i][j]=p.nextInt();
              }
          }
                 
              for(i=0;i<=2;i++)
          {
              for(j=0;j<=3;j++)
              {
                  c[i][j]=0;
                  
                  for(k=0;k<=2;k++)
                  {
                      c[i][j]=c[i][j]+a[i][k]+b[k][j];
                  }
              }
          }
             
             
           System.out.println("Multiplication of matrix is ");
              for(i=0;i<=2;i++)
          {
              for(j=0;j<=3;j++)
              {
                 System.out.print(" "+c[i][j]);
              }
              System.out.println("");
          }
                 
           
       
       
    }
   
}
==============================================================

session2_ex2

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mcs025;

/**
 *
 * @author KETAN
 */
import java.util.*;
public class session2_ex2 {
   
    public static void main(String args[])
    {
        int n,k=0,sum=0;
        Scanner p=new Scanner(System.in);
       
        System.out.println("Enter any number ");
        n=p.nextInt();
        if (n<100000)
        {
            System.out.println("Number should not be less than five digits");
           
        }
        else
        {
        while (n>0)
                {
                   k=n%10;
                   sum=sum+k;
                                              n=n/10;
                }
        System.out.print(sum);
        }
               
               
       
    }
   
}

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

session3_ex1
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mcs025;

/**
 *
 * @author KETAN
 */
import java.util.*;
public class session3_ex1 {
   
    int length,width,area;
    String color;
    void set_length(int l)
    {
        length=l;
    }
    void set_width(int w)
    {
        width=w;
    }
    void set_color(String c)
    {
        color=c;
    }
    int area()
    {
        area=length*width;
        return(area);
       
    }
}

class compare
{
    public static void main(String args[])
    {
        Scanner p=new Scanner(System.in);
        int area1,area2;
        session3_ex1 r1=new session3_ex1();
         session3_ex1 r2=new session3_ex1();
        
         r1.set_length(10);
         r1.set_width(10);
         r1.set_color("a");
         area1=r1.area();
        
         r2.set_length(10);
         r2.set_width(120);
         r2.set_color("a");
         area2=r2.area();
        
         System.out.println("The area1 is "+area1);
         System.out.println("The area2 is "+area2);
        
         if(area1==area2 && r1.color==r2.color)
         {
            System.out.println("Matching ranctangles");
         }
              else
         {
             System.out.println("not matching");
         }
        
               
       
    }
   
}
SHARE

Author: verified_user

0 Comments:

; //]]>