59 lines
1.3 KiB
Java
59 lines
1.3 KiB
Java
package Ueb07;
|
|
|
|
import java.util.*;
|
|
|
|
class Teileranzahl{
|
|
static int in = 0, counter = 0, highest = 1,tmp;
|
|
static Scanner sc;
|
|
public static void main( String[] args){
|
|
do{
|
|
System.out.println("------------------------------------------------------------------------------");
|
|
System.out.println("1 Teileranzahl für n");
|
|
System.out.println("2 Maximale Teileranzahl für die Zahlen 1 bis n");
|
|
System.out.println("3 Fertig");
|
|
System.out.println("------------------------------------------------------------------------------");
|
|
|
|
sc = new Scanner(System.in);
|
|
in = sc.nextInt();
|
|
}while(!(in==1||in==2||in==3));
|
|
switch(in){
|
|
case 1:
|
|
sc = new Scanner(System.in);
|
|
in = sc.nextInt();
|
|
|
|
System.out.println(anzahlTeiler(in));
|
|
break;
|
|
case 2:
|
|
sc = new Scanner(System.in);
|
|
in = sc.nextInt();
|
|
tmp = maxTeiler(in);
|
|
System.out.println(tmp);
|
|
System.out.println(anzahlTeiler(tmp));
|
|
break;
|
|
case 3:
|
|
return;
|
|
}
|
|
sc.close();
|
|
}
|
|
|
|
public static int anzahlTeiler(int input){
|
|
counter = 0;
|
|
for(int i=1; i<=in;i++){
|
|
if(input%i==0){
|
|
counter++;
|
|
}
|
|
}
|
|
return counter;
|
|
}
|
|
|
|
public static int maxTeiler(int input){
|
|
for(int i=1;i<input;i++){
|
|
if(anzahlTeiler(i) > anzahlTeiler(highest)){
|
|
highest = i;
|
|
}
|
|
|
|
}
|
|
return highest;
|
|
}
|
|
}
|