Thursday, January 19, 2017

Interface in java !!

//This program helps you to understand the working of an interface



import java.util.Scanner; //package for scanning purpose
public class Purchase
{
int num,x;
Scanner obj=  new Scanner (System.in);
public void getinfo()
{
System.out.println("Enter the amount of packets purchased: ");
num=obj.nextInt();
System.out.println("Enter amount of defective packets: ");
x=obj.nextInt();

}

public static void main(String[] args)
{
result obj1=new result();
obj1.getinfo();
obj1.amtleft();
stock obj2=new result();
obj2.stk();
obj1.rslt();
}
}
class Preturn extends Purchase
{
int ret;
public void amtleft()
{
System.out.println("Amount left: ");
ret=num-x;
System.out.println(ret);

}
}
interface stock
{
public void stk();
Scanner ob = new Scanner (System.in);

}
class result extends Preturn implements stock
{
int y;

public void stk()
{
System.out.println("Enter previous stock if any: ");


}
public void rslt()
{
y= ob.nextInt();
System.out.println("Packets to be sold : "+(y+ret));
}



}

Friday, January 13, 2017

Print a String In Reverse Order

Program To Print a String In Reverse Order :

import java.util.Scanner;

public class Gndec
{

    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        String name,rev="";
        System.out.println("Enter Your Name");
       
        name=input.nextLine();
        
        System.out.printf("Hello,%s\nIn reverse Order :",name);
        
        int j=0,n=name.length();
        
        for(int i=n-1;i>=0;i--)
        {
           rev=rev+name.charAt(i);
        }
       
        System.out.println(rev);
     
}
}

Output:


Power of 2

Program to Check Whether a Number is Some Power Of 2 (Two):

import java.util.Scanner;

public class Gndec
{

    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        int a,p=0,c=0;
        System.out.println("Enter any Number");
        a=input.nextInt();
        while(a!=1)
        {if(a%2!=0)
        {   p=1;
            System.out.println("No");
            break;
        }
        else{
            a=a/2;
        }
        c++;}
        if(p==0)
        {
            System.out.println("Yes "+c);
        }
}
}

Output:



Thursday, January 12, 2017

HTML Paragraph and New Line Tag

For paragraph HTML has a paragraph tag which is as per given below

<p>any description.....</p>

Following will help you Understand :
<h1>Programming</h1>
<p>"We want every kid in the world to be excited about the many possibilities coding can unlock-for themselves,for their communities and for society.Everyone should have the opportunity to learn computer science at school and beyond".</p>


Output:

Programming

"We want every kid in the world to be excited about the many possibilites coding can unlock-for themselves,for their communities and for society.Everyone should have the opportunity to learn computer science at school and beyond".

For new line HTML has a tag <br>

<br>

This tag has no closing tag.

Following will help you understand:

Gndec Programming<br>
Gndec Programming<br>
Gndec Programming

Output:

Gndec Programming
Gndec Programming
Gndec Programming

Wednesday, January 11, 2017

HTML Heading tag

There are six tags which are used for heading
that is h1,h2,h3,h4,h5,h6  all leads to heading but different size

Following will help you understand :


Tag Desciption
h1

Gndec Programming

h2

Gndec Programming

h3

Gndec Programming

h4

Gndec Programming

h5
Gndec Programming
h6
Gndec Programming



Tuesday, January 10, 2017

HTML Basics

HTML-Hyper Text Markup Language

Basically HTML is used for webpage designing.It has many attributes,tags etc. which helps in designing of web pages

Below Given is a basic HTML Structure
<head>
</head>
<body>
<h1>My First Webpage</h1>
<p>HTML</p>
</body>



headUsed for describing head of a web page
bodyUsed for describing body of a web page
h1Used for heading
(1 to 6 there are headings and these are in descending size)
pUsed for paragraph

You can create your own webpage using any editor say Notepad 
Just write the code in Notepad and save it using .html or .htm extension
Then open the file in any web browser to see what is output

Output:   

Factorial of a Number JAVA

Following Program Illustrates the method of calculating Factorial of a Number:

import java.util.Scanner;
public class JavaApplication1
{

public static void main(String[] args)
{
Scanner input=new Scanner(System.in);

   System.out.println("Enter Any Number to Calculate Factorial");

   int f=1, a=input.nextInt();

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

   { f=f*i;  }

   System.out.println("Factorial is : "+f);

}


}

Output: