Feb 12, 2012

[Java] method without return value

// Java
// method


import java.util.*;

class method
{

// A java program starts with "main" method
 public static void main(String[] args)    // main method
 {
 
        System.out.println("What's your weight in kilogram?");
        Scanner scan1 = new Scanner (System.in);
        
        while(!scan1.hasNextDouble())
        {
            scan1.next();  // if input is not integer value, ignore it.
            System.err.println("Input should be number");
        }
        double weight=scan1.nextDouble(); 
        
        System.out.println("What's your height in centimeter?");
        Scanner scan2 = new Scanner (System.in);
        
        while(!scan2.hasNextDouble())
        {
            scan2.next();  // if input is not integer value, ignore it.
            System.err.println("Input should be number");
        }
        double height=scan2.nextDouble(); 

        if(weight==0) {
            bye();    // if weight was input 0, call method "bye"
            System.exit(0); }
                
        function1(weight, height);   // give "weight" and "height" values to method "fuction1"
        
}

 public static void function1(double weight, double height)
 {
        System.out.println();        
        System.out.println("Calories you daily need = "+(int)(weight*24));
        System.out.println();        
        System.out.println("Recommended weight for you = " + (int)(height-110) + " (female)");
        System.out.println("Recommended weight for you = " + (int)(height-100) + " (male)");        
 }
 
 public static void bye()
 {
        System.out.println();        
        System.out.println("Good Bye");
 }
}

No comments:

Post a Comment