:::: MENU ::::
  • Suitable for all screen sizes

  • Easy to Customize

  • Customizable fonts.

Simple, responsive theme, suitable for personal or corporate blog.

Tuesday, December 29, 2015


Triangle Pattern:


import java.io.*;
public class triangle {
    public static void main (){
        InputStreamReader istream = new InputStreamReader(System.in) ;
        BufferedReader read = new BufferedReader(istream) ;
        System.out.print("Enter Triangle Size : ");
        int num=0;
        try{
            num=Integer.parseInt( read.readLine() );
        } catch(Exception Number){
            System.out.println("Invalid Number!");
        }
            for(int i=1;i<=num;i++){
                for(int j=1;j<num-(i-1);j++){
                    System.out.print(" ");
                }
                for(int k=1;k<=i;k++){
                    System.out.print("*");
                    for(int k1=1;k1<k;k1+=k){
                        System.out.print("*");
                    }
                }
                System.out.println();
            }
    }
}


The result will look like:



Thank You and Like my Facebook Page - ☺ Here 

and

Follow VishuRules on Twitter - @VishuRulesInc

Saturday, December 19, 2015



HCF and LCM of a number:

import java.util.*;

class hcfandlcm

{

    public static void main()

    {

        System.out.println("Enter 2 numbers");

        Scanner sc=new Scanner(System.in);

        int m=sc.nextInt();

        int n=sc.nextInt();

        int h=1;

        int p=m*n;

        for(int i=2;i<p;i++)

        {

            if(m%i==0 && n%i==0)

            {

                h=i;

            }

        }

        int l=p/h;

        System.out.println("HCF= "+h+" and LCM= "+l);

    }

}

Thank You and make sure to Like and Comment.

Factorial of large numbers:

import java.util.Scanner;

import java.math.BigInteger;

class BigFactorial

{

  public static void main()

  {

    int n, c;

    BigInteger inc = new BigInteger("1");

    BigInteger fact = new BigInteger("1");

    Scanner input = new Scanner(System.in);

    System.out.println("Input an integer");

    n = input.nextInt();

    for (c = 1; c <= n; c++) {

      fact = fact.multiply(inc);

      inc = inc.add(BigInteger.ONE);

    }

    System.out.println(n + "! = " + fact);

  }

}

Thank you and make sure to Like and Comment

Factorial of a number:

import java.util.Scanner;

class Factorial

{

   public static void main()

   {

      int n, c, fact = 1;

      System.out.println("Enter a number");

      Scanner in = new Scanner(System.in);

      n = in.nextInt();

      if ( n < 0 )

         System.out.println("Number should be non-negative.");

      else

      {

         for ( c = 1 ; c <= n ; c++ )

            fact = fact*c;

         System.out.println("Factorial of "+n+" is = "+fact);

      }

   }

}

Thank you and make sure to like and comment.


Factors of a Numbers:

import java.util.*;
public class Factors
{
  public static void main()
  {
      int n,i;
      Scanner sc=new Scanner(System.in);
      System.out.println("Enter the Number");
      n=sc.nextInt();
      for(i=1;i<=n;i++)
      {
          if(n%i==0)
          {
            System.out.println(i);
          }
      }
  }
}

Thank you and make sure to like and comment.

Table of a Number:


import java.util.*;
public class Tables
{
    public static void main()
    {
        int n,i,f=1;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter the number");
        n=sc.nextInt();
        for(i=1;i<=10;i++)
        {
            System.out.println(n*i);
        }
    }
}


Thank you and make sure to like and comment.

Wednesday, December 16, 2015


Perimeter of Circle, Rectangle and Circle:

import java.util.Scanner;
public class Perimeter
{
    int r, l, b, s1, s2, s3;
    double pi = 3.14,perimeter;
    Scanner s = new Scanner(System.in);
    void circle()
    {
        System.out.print("Enter radius of circle:");
        r = s.nextInt();
        perimeter = 2 * pi * r;
        System.out.println("Perimeter of circle:"+perimeter);
    }
    void rectangle()
    {
        System.out.print("Enter length of rectangle:");
        l = s.nextInt();
        System.out.print("Enter breadth of rectangle:");
        b = s.nextInt();
        perimeter = 2 * (l + b);
        System.out.println("Perimeter of rectangle:"+perimeter);
    }
    void triangle()
    {
        System.out.print("Enter length of first side of triangle:");
        s1 = s.nextInt();
        System.out.print("Enter length of second side of triangle:");
        s2 = s.nextInt();
        System.out.print("Enter length of third side of triangle:");
        s3 = s.nextInt();
        perimeter = s1 + s2 + s3;
        System.out.println("Perimeter of triangle:"+perimeter);
    }
    public static void main()
    {
        Perimeter obj = new Perimeter();
        obj.circle();
        obj.rectangle();
        obj.triangle();
    }
}

Thank you and make sure to like and comment.

Area of Triangle:

import java.util.Scanner;
class AreaTriangle {
   public static void main() {  
      Scanner scanner = new Scanner(System.in);
      System.out.println("Enter the width:");
      double base = scanner.nextDouble();
      System.out.println("Enter the height:");
      double height = scanner.nextDouble();
      double area = (base* height)/2;
      System.out.println("Area of Triangle is: " + area);    
   }
}

Thank you and make sure to like and comment.

Area of Square:

import java.util.Scanner;
class SquareArea {
   public static void main ()
   {
       System.out.println("Enter Side of Square:");
       Scanner scanner = new Scanner(System.in);
       double side = scanner.nextDouble();
       double area = side*side;
       System.out.println("Area of Square is: "+area);
   }
}

Thank you and make sure to like and comment.

Area and Circumference of a Circle:


import java.util.Scanner;class Circle
{
   static Scanner sc = new Scanner(System.in);
   public static void main()
   {
      System.out.print("Enter the radius: ");
      double radius = sc.nextDouble();
      //Area = PI*radius*radius
      double area = Math.PI * (radius * radius);
      System.out.println("The area of circle is: " + area);
      //Circumference = 2*PI*radius
      double circumference= Math.PI * 2*radius;
      System.out.println( "The circumference of the circle is:"+circumference) ;
   }
}


Thank you and make sure to like and comment.

Swapping the values of two variables without temp variable:

import java.util.*;
public class Swapping
{
  public static void main()
  {
      int x,y;
      Scanner sc=new Scanner(System.in);
      System.out.println("Please enter the numbers you want to swap values of");
      x=sc.nextInt();
      y=sc.nextInt();
      x = x + y;
      y = x - y;
      x = x - y;
      System.out.println("Swapped values are: " +x+", "+y);
     
  }
}
Thank you and make sure to like and comment.

Swapping the values of two variables with temp variable:

import java.util.*;
public class Swapping
{
  public static void main()
  {
      int x,y,temp;
      Scanner sc=new Scanner(System.in);
      System.out.println("Please enter the numbers you want to swap values of");
      x=sc.nextInt();
      y=sc.nextInt();
      temp = x;
      x = y;
      y = temp;
      System.out.println("Swapped values are: " +x+", "+y);
     
  }
}

Thank you and make sure to like and comment.


Division of two numbers with Scanners:

import java.util.*;
public class Div
{
    public static void main()
    {
        Scanner sc=new Scanner(System.in);
        int a,b,result;
        System.out.println("Please enter 2 numbers");
        a=sc.nextInt();
        b=sc.nextInt();
        result=a/b;
        System.out.println("Division is "+result);
    }
}

Thank you and make sure to like and comment.


Multiplication of two numbers with Scanners:

import java.util.*;
public class Multi
{
    public static void main()
    {
        Scanner sc=new Scanner(System.in);
        int a,b,result;
        System.out.println("Please enter 2 numbers");
        a=sc.nextInt();
        b=sc.nextInt();
        result=a*b;
        System.out.println("Multiplication is "+result);
    }
}

Thank you and make sure to like and comment.

Subtraction of two numbers with Scanners:

import java.util.*;
public class Subtract
{
    public static void main()
    {
        Scanner sc=new Scanner(System.in);
        int a,b,result;
        System.out.println("Please enter 2 numbers");
        a=sc.nextInt();
        b=sc.nextInt();
        result=a-b;
        System.out.println("Subtraction is "+result);
    }
}

Thank you and make sure to like and comment.

Add two numbers with Scanners:

import java.util.*;
public class Sum
{
    public static void main()
    {
        Scanner sc=new Scanner(System.in);
        int a,b,sum;
        System.out.println("Please enter 2 numbers");
        a=sc.nextInt();
        b=sc.nextInt();
        sum=a+b;
        System.out.println("Sum is "+sum);
    }
}


Thank you and make sure to like and comment.


Divide two numbers:

public class Divide
{
    public static void main()
    {
        int a,b,result;
        a=20;
        b=10;
        result=a/b;
        System.out.println("Division is "+result);
    }
}

Thank you and make sure to like and comment.

A call-to-action text Contact us