Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ciklusokgyakorlas;
- public class CiklusokGyakorlas {
- public static void main(String[] args) {
- //Szám osztói
- int x = 27;
- //legkisebb
- for ( int i = 2; i <= x-1; i++ ) {
- if ( x % i == 0 ) {
- System.out.println(i);
- break;
- }
- }
- //legkisebb v2.
- int i = 2;
- while (x % i != 0) {
- i++;
- }
- if (x == i) {
- System.out.println("prím");
- } else {
- System.out.println(i);
- }
- /*
- //Opt. változat
- for ( int i = 2; i*i <= x; i++ ) {
- if ( x % i == 0 ) {
- System.out.println(i);
- System.out.println(x/i);
- }
- }
- */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement