Jump to content

[Resolvido] Duvida de novato


Recommended Posts

Sou novato e estou com um problema.

package Probabilidade;

import java.util.Scanner;

public class Ler {

 static Scanner leia = new Scanner(System.in);

 public static void main(String args[]){

   int factorialN = 1;
   int factorialR = 1;
   int NcR;

   System.out.println("Digite o numero de objectos");
   int n = leia.nextInt();
   System.out.println("Digite o numero de objectos que são retirados");
   int r = leia.nextInt();

   for(int a = n; n == 1; n--){
     factorialN = factorialN*n;
     System.out.println("Sou "+ factorialN);
   for(int b = r; r == 1; r--){
     factorialR = factorialR*r;
     System.out.println("Eu 2º sou "+ factorialR);

   NcR = factorialN/(factorialR*(factorialN-factorialR));

   System.out.println("O numero de combinações é "+ NcR);

o erro que me dá é na linha NcR = factorialN/(factorialR*(factorialN-factorialR)); e é o seguinte:

Exception in thread "main" java.lang.ArithmeticException: / by zero

at Probabilidade.Ler.main(Ler.java:30)

Alguém me pode dizer onde estou a errar sff.


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.