mardi 11 octobre 2016

Create method that prints the numbers between two specified numbers

So I'm creating a method in that is supposed to print the numbers between two specified numbers. I had it setup before in the main method but i can figure out how to make a method and call it into the main method. What my program does right now is it only prints what "int between" is equal to. I don't want anyone to just type the code out for me, i'm just looking for tips on what i should change. Last time i asked a question someone proceeded to just answer with code and it did not help me to learn anything.

So my question is what is causing the program to only display what between is equal to? I know that I need a value for the if loop to return something, but it needs to return the numbers between num1 & num2. My Professor Also said that the method needs to be "public static void Printer(int num1, int num2)" is that even possible? I kept getting an error so I switched to "int Printer".

package nortonaw_Assignment8;

public class Nortonaw_Assignment8 {

    public static void main(String[] args) {
        int between;
        between = Printer(5, 20);
        System.out.println(between);
    }
public static int Printer (int num1, int num2){
    int between = 0;
    for (;num1<=num2; num1++);
    return between;
    }
}

Aucun commentaire:

Enregistrer un commentaire