164 lines
2.6 KiB
Java
Executable File
164 lines
2.6 KiB
Java
Executable File
|
|
/**
|
|
* Beschreiben Sie hier die Klasse Methoden.
|
|
*
|
|
* @author (Ihr Name)
|
|
* @version (eine Versionsnummer oder ein Datum)
|
|
*/
|
|
public class Methoden
|
|
{
|
|
public static float quadrat(float x)
|
|
{
|
|
float quadrat = x*x;
|
|
return quadrat;
|
|
}
|
|
public static void test()
|
|
{
|
|
float a = quadrat(5);
|
|
System.out.println("Das Quadrat von 5 ist" + a);
|
|
}
|
|
public static int summe(int a,int b)
|
|
{
|
|
int summe = a+b;
|
|
System.out.println(summe);
|
|
return summe;
|
|
|
|
}
|
|
public static int differenz( int a,int b)
|
|
{int differenz = a-b;
|
|
System.out.println(differenz);
|
|
return differenz;
|
|
|
|
}
|
|
public static int produkt( int a,int b)
|
|
{int produkt = a*b;
|
|
System.out.println(produkt);
|
|
return produkt;
|
|
|
|
}
|
|
public static int quotient( int a,int b)
|
|
{int quotient = a/b;
|
|
System.out.println(quotient);
|
|
return quotient;
|
|
|
|
}
|
|
public static int term()
|
|
{ return produkt(3, summe(2,5));
|
|
}
|
|
public static double potenz(double a,int b)
|
|
{
|
|
|
|
/**
|
|
* Berechnet die Potenz a hoch b
|
|
*/
|
|
double zwischenergebnis = 1;
|
|
for(int i = 0;i<b;i++ )
|
|
{
|
|
zwischenergebnis = zwischenergebnis * a;
|
|
|
|
}
|
|
return zwischenergebnis;
|
|
}
|
|
public static int max(int a ,int b)
|
|
{
|
|
if(a<b)
|
|
{
|
|
return b;
|
|
}
|
|
else
|
|
{
|
|
return a;
|
|
}
|
|
}
|
|
public static int min(int a,int b)
|
|
{ if(a<b)
|
|
{
|
|
return a;
|
|
}
|
|
else
|
|
{
|
|
return b;
|
|
}
|
|
}
|
|
public static int abs(int a)
|
|
{
|
|
if(a>0)
|
|
{
|
|
return a;
|
|
}
|
|
else
|
|
{
|
|
return -a;
|
|
}
|
|
}
|
|
public static int round(double zahl)
|
|
{
|
|
int vorkomma = (int) zahl;
|
|
double nachkomma = zahl - vorkomma;
|
|
|
|
if(nachkomma<0.5)
|
|
{
|
|
return vorkomma;
|
|
}
|
|
else
|
|
{
|
|
return vorkomma + 1;
|
|
|
|
|
|
}
|
|
}
|
|
public static boolean istGross(int a)
|
|
{
|
|
if(a<1000)
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
public static boolean istmaesigGross(int a)
|
|
{
|
|
int betrag = abs(a);
|
|
if(betrag>1000 )
|
|
{return true;
|
|
}
|
|
else
|
|
{return false;
|
|
}
|
|
}
|
|
public static boolean istGerade(int a)
|
|
{
|
|
if(a % 2 == 0)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
public static boolean istTeilbar(int a,int b)
|
|
{
|
|
if(a % b == 0)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
public static boolean istPrim(int a)
|
|
{
|
|
for(int i=2;i< a/2;i++)
|
|
{
|
|
if(a % i == 0)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
} |