elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Sigue las noticias más importantes de seguridad informática en el Twitter! de elhacker.NET


  Mostrar Temas
Páginas: [1]
1  Programación / Java / Problema con enteros muy grandes en Java en: 31 Marzo 2014, 18:15 pm
Hola a todos

Estoy haciendo un ejercicio en Java que solicita calcular si un número de 25 cifras o mayor es primo o no, funciona correctamente hasta 18 cifras, pero de ahí en adelante no deja hacer nada, agradezco quien me pueda dar una manita a ver que puede estar faltando

Código:
import javax.swing.*;
import java.awt.*;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class NP
{
    public static void main(String args[]) throws NumberFormatException, IOException, FileNotFoundException
    {      
      
        long A=0;
        int div=0;
        int B = 1;
        float raiz;
        
        BufferedReader leer = new BufferedReader(new InputStreamReader(System.in));
        
        System.out.println("");
System.out.print("Digite el Número:  ");
System.out.print("");
A = (long) Double.parseDouble(leer.readLine());
raiz = (float) Math.sqrt(A);

        if( A > 0 )
        {
          
            for ( B = 1; B <= raiz; B++)              
            {
          
                if(A % B == 0)
                {
                    div++;
                }
            }
            
            if(div<=2)
            {
                
             System.out.println("");
         System.out.print(A+" Si es un número Primo");
         System.out.print("");
            }
            else
            {
             System.out.println("");
         System.out.print(A+" No es un número Primo");
         System.out.print("");
            }
        }
          
    }
}

Muchas gracias por su ayuda
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines