This site requires JavaScript, please enable it in your browser!
Greenfoot back
someone1
someone1 wrote ...

2015/8/18

need help with returning method

someone1 someone1

2015/8/18

#
This is a different question than before I want to display my method value to the user but answer is always 0.0
static double numbersOne, numbersTwo, numbersThree;
import java.util.Scanner;

public void mainMethod() {
import java.util.Scanner; 
Scanner keyboard = new Scanner(System.in)
numbers();
System.out.print("Enter a number");
numbersTwo = keyboard.nextDouble();
System.out.print("Enter another number");
numbersThree = keyboard.nextDouble();
 System.out.print(numbers());
}

public static double numbers() {
 numbersOne = (numbersTwo * numbersThree)  /  115;
return numbersOne;

}
someone1 someone1

2015/8/18

#
i want display numbers, just for clarification
Super_Hippo Super_Hippo

2015/8/18

#
You could use the 'ask' method:
    public void mainMethod()
    {
        double a = Integer.parseInt(Greenfoot.ask("Enter a number"));
        double b = Integer.parseInt(Greenfoot.ask("Enter another number"));
        System.out.print(((a*b)/115));
    }
danpost danpost

2015/8/18

#
For one thing, lines 2 and 5 should be outside the code-block of the class itself and you only need it once. Another thing is line 7 -- calling a method that returns a value, but not doing anything with that value is pointless (you can remove that line without changing anything). I think it might be best if you show the entire class code. It appears you posted only those parts you felt might be important; but, with your lack of knowledge in how a class is constructed, posting the entire thing would be in order.
someone1 someone1

2015/8/18

#
Thanks for ur guys help,I already found an answer, but i will take note about the classes part
You need to login to post a reply.