Tuesday, December 10, 2013

Method with return type in JAVA : Day 4



a) How Method return a value? Write necessary Syntax.

b) Write any JAVA program that takes parameters in a Method.

26 comments:

  1. *********Write any JAVA program that takes parameters in a Method.

    Source code:

    package Box;

    public class Box
    {
    public double width;
    public double depth;
    public double height;
    public Box(double width,double depth,double height)
    {
    this.width=width;
    this.depth=depth;
    this.height=height;
    }
    public double calculate()
    {
    double volume = width*depth*height;
    return volume;
    }
    public static void main(String[] args)
    {
    Box box = new Box(5,4,3);
    double volumeOfBox = box.calculate();
    System.out.println("The volume is " + volumeOfBox);
    }
    }

    ReplyDelete
  2. a))) ***How Method return a value? Write necessary Syntax.

    A method returns to the code that invoked it when it:

    1.completes all the statements in the method,
    2.reaches a return statement, or
    3.throws an exception (covered later) whichever occurs first.

    Need to declare a method's return type in its method declaration. Within the body of the method use the return statement

    to return the value.
    Any method declared void doesn't return a value. It does not need to contain a return statement, but it may do so. In such

    a case, a return statement can be used to branch out of a control flow block and exit the method and is simply used like

    this:

    return;

    If try to return a value from a method that is declared void, ir will be a compiler error.
    Any method that is not declared void must contain a return statement with a corresponding return value, like this:

    return returnValue;

    ReplyDelete
  3. b) Write any JAVA program that takes parameters in a Method.


    public class Box

    {
    public double calvol(double width,double heigth ,double depth)

    {

    return width*heigth*depth;

    }
    }


    public class Ob {

    public static void main(String[] args) {

    Box b1 = new Box();

    double vol;

    vol = b1.calvol(11,12,14);

    System.out.println("The volum is : " + vol);


    }

    }

    ReplyDelete
  4. *******a) How Method return a value? Write necessary Syntax.**********

    Solution:
    Returning value from the method: We can specify return type of the method as "primitive data type" or

    "class name". Return type can be be "void" means it does not return any value. Method can return a

    value by using "return" keyword.

    e.g. int len = R1.getLength( );

    Example of returning value from the method:

    Source code:

    package square;
    public class Square
    {
    double length;
    double width;

    void setLength(int len)
    {
    length = len;
    }

    double getLength()
    {
    return length;
    }
    }

    class SquareDemo
    {
    public static void main(String args[])
    {
    Square s1 = new Square();
    s1.setLength(20.5);
    double len = s1.getLength();

    System.out.println("Length of a Square : " + len);
    }
    }

    ReplyDelete
    Replies
    1. here is a typing mistake *void setLength(int len).....it will be *void setLength(double len)

      Delete
  5. This information you provided in the blog that was really unique I love it!!, Thanks for sharing such a great blog..Keep posting..

    JAVA J2EE Training in Chennai

    ReplyDelete
  6. Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.
    Best Final Year Project Center in Chennai | No.1 Diploma Project in Chennai | Best BBA/MBA Project Center in Chennai


    ReplyDelete
  7. Hadoop Training Institute in Noida- Webtrackker is the best Hadoop training institute in noida. If you want take the training in a Hadoop than Webtrackker is the best option for you. Since then Hadoop has continued with the development of the YARN cluster manager, releasing the project from its first distribution of HadoopMap Reduce. HadoopMap Reduce is still available in Hadoop to perform static batch processes for which Map Reduce is suitable. Other data processing activities can be assigned to different processing engines (including Spark), where YARN manages the management and allocation of cluster resources.
    Projects like Apache Mesas provide a powerful and growing range of distributed cluster management capabilities. Most Spark implementations still use Apache Hadoop and its associated projects to meet these requirements.

    ReplyDelete
  8. Webtrackker Indirapuram offers an inclusive software testing training in Indirapuram. The extensive practical training provided by the Software Testing training institute in Indirapuram, equips live projects and simulations. Such a detailed course in Software Testing has helped our students to obtain work in several multinationals. The Webtrackker trainers are subject to specialized corporate professionals who offer an in-depth study in the Software Testing course in Indirapuram.
    software testing institute in Indirapuram

    ReplyDelete
  9. Webtrackker is the best Salesforce online training in india, Do not assume that all sales employees have understood how the training should be applied. Sales training is largely generic. There may be a gap between knowing how to apply a principle. You want to make sure you close that gap. If necessary, take a new language. If the training requires a new language or terms that you have not used before, adjust the new terms as part of your sales vocabulary. This will help strengthen the training. Webtrackker is the best training in India Do not conduct sales training that is not in line with your sales philosophy. Before investing in a sales training program, make sure the curriculum matches your sales philosophy. For example, if you use a strategic sales process, do not send your salespeople to training that focuses primarily on tactics and not strategies. Keep the goals of the sales team members that you want to achieve with the salesforce training before the salesforce training begins. Knowing what you want to stop training before you start training is very valuable.
    Aws online training in india
    Salesforce online training in india

    ReplyDelete
  10. Great post!I am actually getting ready to across this information, I am very happy to this commands.Also great blog here with all of the valuable information you have.Well done, it's a great knowledge.
    BE/B.Tech Project Center in Chennai | ME/M.Tech Project Center in Chennai | Final Year Project Center in Chennai

    ReplyDelete
  11. CIITN Noida provides Big data hadoop training in Noida & hadoop training institute in noida based on current industry standards that helps attendees to secure placements in their dream jobs at MNCs. CIITN Provides Best Big Data Training in Noida. CIITN is one of the most credible Big Data training institutes in Noida offering hands on practical knowledge and full job assistance with basic as well as advanced level Big Data training courses. At CIITN Big Data training in noida is conducted by subject specialist corporate professionals with 7+ years of experience in managing real-time Big Data projects. CIITN implements a blend of academic learning and practical sessions to give the student optimum exposure that aids in the transformation of naïve students into thorough professionals that are easily recruited within the industry.
    CIITN is the best Hadoop training center in Noida with a very high level infrastructure and laboratory facility. The most attractive thing is that candidates can opt multiple Institute.

    Big data hadoop training in Noida & hadoop training institute in noida

    ReplyDelete
  12. CIITN provides Best Linux training in noida based on current industry standards that helps attendees to secure placements in their dream jobs at MNCs. CIITN Provides Best Linux Training in Noida. CIITN is one of the most credible offering hands on practical knowledge and full job assistance with basic as well as advanced level.

    best linux training institute in noida

    linux training in noida

    ReplyDelete
  13. nice post it help yo every java dedicated student for java course visit java summer training

    ReplyDelete
  14. It's really nice & helpful!Thanks for sharing the clear picture about Java.
    You have clearly explained about the java programming more informative manner for all.I would like to share.Keep updating good stuff.
    sap training

    ReplyDelete
  15. Nice post keep do posting The Info was too good....
    For more information about aws please click here: AWS Training In Hyderabad

    ReplyDelete