Created
January 15, 2019 00:13
-
-
Save somahargitai/1d507481bc7fca1b8f52a61be96229f0 to your computer and use it in GitHub Desktop.
Tökéletes Szám ellenőrzés
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TokeletesDetektorClass{ | |
public static void main(String []args){ | |
System.out.println("Hello World"); | |
int tokeletese1 = 6; | |
int tokeletese2 = 7; | |
System.out.println(tokeletesSzamDetektor(tokeletese1)); | |
System.out.println(tokeletesSzamDetektor(tokeletese2)); | |
} | |
public static boolean tokeletesSzamDetektor(int bemenet) { | |
int osztoosszeg = 1; | |
for(int i = 2; i <= bemenet / 2; i++) { | |
if(bemenet % i == 0) { | |
osztoosszeg += i; | |
} | |
} | |
if(osztoosszeg == bemenet) return true; | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment