Skip to content

Instantly share code, notes, and snippets.

@somahargitai
Created January 15, 2019 00:13
Show Gist options
  • Save somahargitai/1d507481bc7fca1b8f52a61be96229f0 to your computer and use it in GitHub Desktop.
Save somahargitai/1d507481bc7fca1b8f52a61be96229f0 to your computer and use it in GitHub Desktop.
Tökéletes Szám ellenőrzés
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