Practicos01 - p int n = 0; String user =...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
import*; import java.util.*; i public class Practicos01{ p public static Scanner teclado = new Scanner(; p public static boolean esPerfecto(int n){ int acum = 0; for(int i=1; i<=n/2 ; i++){ if(n%i==0) acum+=1;} if(acum == n) return true; else return false;} r //Una variable acumuladora siempre la tengo que inicializar //Para utilizar una variable siempre tengo que declararla //Si no voy a utilizar su valor inmediatamente puedo no inicializarla i public static void main(String args[]){
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: p int n = 0; String user = &quot;&quot;; do{ System.out.print(&quot;Dime un nmero entero: &quot;); n = teclado.nextInt(); n // *** Dos formas de llamar a un boolean *** boolean b = esPerfecto(n); b // if(esPerfecto(n)==true) System.out.println(&quot; &amp; El nmero &quot; +n+ &quot; es perfecto.&quot;); else System.out.println(&quot; &amp; El nmero &quot; +n+ &quot; no es perfecto.&quot;); p System.out.println(&quot;\nDeseas continuar? &quot;); user =; }while(user.equals(&quot;si&quot;)); } } }...
View Full Document

Ask a homework question - tutors are online