Translate

Sunday, 10 December 2017

java program area

import java.util.Scanner;

public class Parallelogram

{

    public static void main(String[] args) 

    {

        int a, b,area;

        Scanner s = new Scanner(System.in);

        System.out.print("Enter the base of parallelogram:");

        a = s.nextInt();

        System.out.print("Enter the height of the parallelogram:");

        b = s.nextInt();

        area = a * b;

        System.out.println("Area of parallelogram:"+area);

    }

}


Output:


Enter the base of parallelogram:5

Enter the height of the parallelogram:6

Area of parallelogram:30

Pattern in Java

      Pattern in Java

class NumberPattern

{

 public static void main(String[] args) 

 {

 for (int i = 1; i <= 5; i++) 

 {

 for (int j = 1; j <= i; j++)

 {

 System.out.print(j+" ");

 }

 System.out.println();

 }

 }

}

 

                 User code 


import java.util.Scanner;

 

public class MainClass

{

    public static void main(String[] args) 

    {

        Scanner sc = new Scanner(System.in);

         

        //Taking rows value from the user

         

        System.out.println("How many rows you want in this pattern?");

         

        int rows = sc.nextInt();

         

        System.out.println("Here is your pattern....!!!");

         

        for (int i = 1; i <= rows; i++) 

        {

            for (int j = 1; j <= i; j++)

            {

                System.out.print(j+" ");

            }

             

            System.out.println();

        }

         

        //Close the resources

         

        sc.close();

    }

}


                 Output 



1 2 

1 2 3 

1 2 3 4 

1 2 3 4 5

Featured post

check box

<!DOCTYPE html> <html> <head>   <title>Check Box</title> </head> <body>   <input ty...