Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Squaring of two number in Static class 
 

In this section we will learn how to use static method and how can display multiplication of two any number. The static method use no instance variables of any object of the class they are defined in example.

 

Squaring of two number in Static class

                         

In this section we will learn how to use static method and how can display multiplication of two any number. The static method use no instance variables of any object of the class they are defined in example. 

Description of program
Here this program calculate the any two number . First of all, we have to define class named "StaticSquare" . To square a static method  are define main class and passing the two parameter of integer type values. Then we have to define the two integer type values in the class method. We are going to create object for calling the two number by using this method "staticSquare.main(a,b)" and after that "staticSquare.square1()" is return the integer type values for x and "staticSquare.square2()" is return the integer type values for y value. Now we are going to used parseInt method for converting the argument value into the string values. So output will be display on the screen by using the System.out.println() method in the command prompt.

Here is the code of this program

import java.io.*;

class StaticSquare {
  public static int x;
  public static int y;
  public static void main(int x1, int y1){
   x=x1;
   y=y1;
   }
    public int square1(){
    return (x*x);
    }
    public int square2(){
    return (y*y);
    }
    public static void main(String args[]){
      try{
        StaticSquare staticSquare=new StaticSquare();
        BufferedReader sq=new BufferedReader (new InputStreamReader(System.in));
        System.out.println("Enter two number");
        int a=Integer.parseInt(sq.readLine());
        int b=Integer.parseInt(sq.readLine());
        staticSquare.main(a,b);
        System.out.println("value1 is=" + a);
        System.out.println("value2 is="+ b);  
        int sq1=staticSquare.square1();
        int sq2=staticSquare.square2();    
        System.out.println("square of value1 is= " + sq1);
        System.out.println("square of value2 is= "+ sq2);  
        }
        catch(Exception e){}
    }
}

Download this example

                         

» View all related tutorials
Related Tags: c array convert vector io this to learn ear e il section in tor s ctor is ll ray ea

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.