Tuesday, January 24, 2017

Number Pattern 3 :)-By Navneet Singh

Following code will print the following pattern:

 1   2   3   4   5 
 6   7   8   9  10
11 12 13 14 15
16 17 18 19 20

Code::

import java.util.*;
public class Pattern 
{
    public static void main(String[] nt) 
    {  
        int a[][]=new int[20][20];
        System.out.println("Enter The Number of Rows");
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        System.out.println("Enter Number of Columns");
        int m=in.nextInt();
        int k=1;
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                a[i][j]=k++;
                        
            }
        }
        System.out.println("Pattern is :");
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                System.out.print(a[i][j]+" ");
            }
            System.out.println();
        }
       

    }

Output:


Special Thanks To Mr.Navneet Singh For This Program....

Number Pattern 2 Java :)-By Piyush Arora

Following code will print the following pattern:

1
2 6
3 7 10 
4 8 11 13
5 9 12 14 15


Code::

import java.util.*;
public class Pattern 
{
    public static void main(String[] nt) 
    {  
        int a[][]=new int[20][20];
        System.out.println("Enter The Number of Rows");
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        int k=1;
        for(int i=1;i<=n;i++)
        {
            for(int j=i;j<=n;j++)
            {
                a[j][i]=k++;
                        
            }
        }
        System.out.println("Pattern is :");
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=i;j++)
            {
                System.out.print(a[i][j]+" ");
            }
            System.out.println();
        }
       

    }

Output:


Special Thanks To Mr.Piyush Arora for This Program....

Number Pattern Java :)- By Garvit Abbat

Following code will print a pattern like given below:

0
1 2
3 4 5
6 7 8 9

Code::

import java.util.*;
public class Pattern 
{
    public static void main(String[] nt) 
    {  
        int a[][]=new int[20][20];
        System.out.println("Enter The Number of Rows");
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        int k=0;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=i;j++)
            {
                a[i][j]=k++;
            }
        }
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=i;j++)
            {
                System.out.print(a[i][j]+" ");
            }
            System.out.println();
        }
       
    }
    

}

Output:




Special Thanks to Mr. Garvit Abbat for this Program.....

How to create a Doraemon :) - By Nikita Sarna

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
public class doreme extends Applet{



public void paint(Graphics gr)
{
gr.setColor(Color.white);
gr.fillOval(204,405,65,40);
gr.setColor(Color.black);
gr.drawOval(204,405,65,40);
//left leg
gr.setColor(Color.white);
gr.fillOval(282,405,65,40);
gr.setColor(Color.black);
gr.drawOval(282,405,65,40);
//right leg
int x[]={200,350,400,420,348,340,290,275,260,210,218,188,168};
int y[]={250,250,200,220,300,420,420,380,420,420,310,360,340};
gr.setColor(Color.blue);
gr.fillPolygon(x,y,13);
gr.setColor(Color.blue);
gr.fillPolygon(x,y,13);
//body
gr.setColor(Color.white);
gr.fillOval(223,240,115,125);
gr.setColor(Color.black);
gr.drawOval(223,240,115,125);
gr.drawLine(240,310,320,310);
gr.drawArc(240,270,80,80,180,180);
//head
gr.setColor(Color.BLUE);
gr.fillOval(170,85,210,180);
gr.setColor(Color.black);
gr.drawOval(170,85,210,180);
//face
gr.setColor(Color.WHITE);
gr.fillOval(188,125,175,135);
gr.setColor(Color.black);
gr.drawOval(188,125,175,135);
//mouth
gr.setColor(Color.black);
gr.drawLine(230,198,325,200);
gr.drawArc(230,155,95,87,180,180);
gr.setColor(Color.black);
gr.fillArc(230,155,95,87,180,180);
//tongue
gr.setColor(Color.black);
gr.drawArc(255,214,50,40,-170,-170);
gr.setColor(Color.red);
gr.fillArc(255,214,50,40,-170,-190);
gr.fillArc(255,227,48,15,180,180);
//left eye
gr.setColor(Color.white);
gr.fillOval(232,100,45,60);
gr.setColor(Color.black);
gr.drawOval(232,100,45,60);
//right eye
gr.setColor(Color.white);
gr.fillOval(278,100,45,60);
gr.setColor(Color.black);
gr.drawOval(278,100,45,60);
//left pupil
gr.setColor(Color.black);
gr.fillOval(255,125,14,24);
//right pupil
gr.setColor(Color.black);
gr.fillOval(285,125,14,24);
//left inner eye part
gr.setColor(Color.white);
gr.fillOval(259,135,7,7);
//right inner eye part
gr.setColor(Color.white);
gr.fillOval(288,135,7,7);

//nose
gr.setColor(Color.red);
gr.fillOval(260,148,34,34);
gr.setColor(Color.black);
gr.drawOval(260,148,34,34);
//nose inner
gr.setColor(Color.white);
gr.fillOval(265,158,10,10);
gr.setColor(Color.black);
gr.drawOval(265,158,10,10);
//moustache line
gr.drawLine(278,181,278,198);
gr.drawLine(310,170,368,150);
gr.drawLine(310,180,368,180);
gr.drawLine(310,190,368,210);
gr.drawLine(240,170,188,150);
gr.drawLine(240,180,188,180);
gr.drawLine(240,190,188,210);
      //necklace
gr.setColor(Color.red);
gr.fillRect(215,248,120,15);
//
gr.setColor(Color.black);
//
gr.drawRect(215,248,120,15);
//bell
gr.setColor(Color.yellow);
gr.fillOval(260,250,40,40);
gr.setColor(Color.black);
gr.drawOval(260,250,40,40);
//bell inner part
gr.setColor(Color.black);
gr.fillOval(274,270,10,10);
gr.setColor(Color.black);

// bell lines
gr.drawArc(253,265,50,20,30,100);

//left hand
gr.setColor(Color.white);
gr.fillOval(158,330,40,40);
gr.setColor(Color.black);
gr.drawOval(158,330,40,40);
//right hand
gr.setColor(Color.white);
gr.fillOval(390,190,40,40);
gr.setColor(Color.black);
gr.drawOval(390,190,40,40);

}
}
-

Monday, January 23, 2017

Lottery Odds

Program to calculate Lottery Odds of a Lottery Draw :

Lottery OddsIn a typical 6/49 game, each player chooses six non-duplicate numbers from a range of 1-49. If the six numbers on a ticket match the numbers drawn by the lottery, the ticket holder is a jackpot winner—regardless of the order of the numbers. The probability of this happening is 1 in 13,983,816.

Following is the code to find lottery odds:

import java.util.*;
public class Lottery 
{

   
    public static void main(String[] nt) 
    {
        
        Scanner in=new Scanner(System.in);
        System.out.println("Enter Total Numbers");
        int a=in.nextInt();
        System.out.println("Enter Total Numbers to draw");
        int b=in.nextInt();
        double lottery=1;
        for(int i=1;i<=b;i++)
        {
            lottery=lottery*(a-i+1)/i;     //combination
        }
        System.out.println("Total Lottery odds are "+lottery);
    }
    

}

Output:

Sunday, January 22, 2017

Fibonacci Sequence Java

Following code will help you understand:

import java.util.*;
public class Fibonacci {
    public static void main(String[] nt)
    {   int a=0,b=1,next;
        Scanner in=new Scanner(System.in);
        { System.out.println("Enter Number of Terms");
        int n=in.nextInt();
        if(n<1)
        {
            System.out.println("Invalid No of Terms !! Please Try Again");
        }
        
        else if(n==1)
        {     System.out.println("Terms are");
               System.out.println(a);
        }
        else
        {   System.out.println("Terms are");
            System.out.print(a+" "+b+" ");
            for(int i=3;i<=n;i++)
            {
                next=a+b;
                System.out.print(next+" ");
                a=b;b=next;
            }
            System.out.println();
        }
    
     }
}

}

Output:


Prime Numbers Upto N Java

Following code prints all prime numbers upto user defined N:

import java.util.*;
public class Prime {
    public static void main(String[] nt)
    {
        Scanner in=new Scanner(System.in);
        System.out.println("Enter Max Limit");
        int n=in.nextInt();
        int a=2,p=0;
        do
        {
            for(int c=2;c<=a/2;c++)
            {
                if(a%c==0)
                {
                    p=1;
                    break;
                }
            }
            if(p==0)
            {
                System.out.print(a+" ");
            }
            a++;
            p=0;
        }
        while(a<=n);
    }

}

Output: