Házi feladat
Alapfejezet - A ló gikája avagy a döntés logikája (páros vagy páratlan)
Hangyási Mátyás előzetesen felállított matematikai alapelvek alapján számok oszthatóságát, valamint páros-páratlan tulajdonságait implementálta kódjában.
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int z = 0;
int x = 0;
int y = 0;
System.out.println("This program tests if a number is dividable by 6, 10, 15
and if it is an odd or even number.");
do{
System.out.println("How many numbers
would you like to test?");
y = scan.nextInt();
for(int i = 0; i < y; i++){
System.out.println("Type in an integer");
x =
scan.nextInt();
if(x % 2 == 0
&& x % 3 == 0){
System.out.println("Your number is dividable by 6");
}
if(x % 5 == 0
&& x % 3 == 0){
System.out.println("Your number is dividable by 15");
}
if(x % 2 == 0
&& x % 5 == 0){
System.out.println("Your number is dividable by 10");
}
if(x % 2 ==
0){
System.out.println("Your number is even.");
}
else{
System.out.println("Your number is odd.");
}
}
System.out.println("Would you like to
test other numbers? If so then press '1'.");
try{
z =
scan.nextInt();
}
catch(Exception e){}
}while(z == 1);
System.out.print("Kilépés...");
}
}
Végeredmény:
This program tests if a number is dividable by 6, 10, 15 and if it is an odd
or even number.
How many numbers would you like to test?
3
Type in an integer
54
Your number is dividable by 6
Your number is even.
Type in an integer
42
Your number is dividable by 6
Your number is even.
Type in an integer
2
Your number is even.
Would you like to test other numbers? If so then press '1'.
1
How many numbers would you like to test?
1
Type in an integer
33
Your number is odd.
Would you like to test other numbers? If so then press '1'.
0
Kilépés...