mercredi 11 octobre 2017

Enter an integer and use jump factorial

I have tried everything I can think of but nothing is working for this problem...

Prompt the user to enter an integer n.

  • If n is odd, then compute the following jump-factorial: 1*3*5*7*…*n;
  • If n is even, compute the following jump-factorial: 2*4*6*…*n;
  • if n is negative or zero, the result is 0.

Finally, output the result.

import java.util.Scanner;
public class problem10 {
    public static void main(String[] args) {

        // part 1: open scanner
        Scanner sc = new Scanner(System.in);

        // part 2: prompt user to enter a number
        System.out.println("Please enter an integer: ");
        double num = sc.nextDouble();

        // part 3: tell whether number is odd or even
        for (int i=0; i>0; i+=2) {
            if(i%2);
        }
    }
}

That's all I have, but I don't know what to do to tell if the number is even because I can't use integer or double with boolean.

Aucun commentaire:

Enregistrer un commentaire