178 lines
3.0 KiB
Java
178 lines
3.0 KiB
Java
import java.util.Scanner;
|
|
|
|
public class Anfang
|
|
{
|
|
public static void Aufgabe1() {
|
|
String test = "Hello_World!";
|
|
|
|
|
|
for(int i = 11; i >(-1); i--)
|
|
{
|
|
System.out.println( test.charAt(i) );
|
|
}
|
|
}
|
|
|
|
public static void Aufgabe2() {
|
|
|
|
Scanner Sc = new Scanner (System.in);
|
|
int eingabe = Sc.nextInt();
|
|
|
|
|
|
System.out.println(eingabe + "Sekunden entsprechen");
|
|
System.out.println(eingabe/60/60/24/365 + "Jahren");
|
|
System.out.println(eingabe/60/60/24 + "Tagen");
|
|
System.out.println(eingabe/60/60 + "Stunden");
|
|
System.out.println(eingabe/60 + "Minuten");
|
|
System.out.println(eingabe + "Sekunden");
|
|
}
|
|
|
|
public static void Aufgabe3()
|
|
{
|
|
for(int i = 1; i < 11; i++)
|
|
{
|
|
System.out.print(i);
|
|
}
|
|
for(int i= 1; i < 11; i++)
|
|
{
|
|
System.out.print(i*2);
|
|
}
|
|
for(int i= 1; i < 11; i++)
|
|
{
|
|
System.out.print(i*3);
|
|
}
|
|
for(int i= 1; i < 11; i++)
|
|
{
|
|
System.out.print(i*4);
|
|
}
|
|
for(int i= 1; i < 11; i++)
|
|
{
|
|
System.out.print(i*5);
|
|
}
|
|
for(int i= 1; i < 11; i++)
|
|
{
|
|
System.out.print(i*6);
|
|
}
|
|
for(int i= 1; i < 11; i++)
|
|
{
|
|
System.out.print(i*7);
|
|
}
|
|
for(int i= 1; i < 11; i++)
|
|
{
|
|
System.out.print(i*8);
|
|
}
|
|
for(int i= 1; i < 11; i++)
|
|
{
|
|
System.out.print(i*9);
|
|
}
|
|
for(int i= 1; i < 11; i++)
|
|
{
|
|
System.out.print(i*10);
|
|
}
|
|
}
|
|
public static void Summe()
|
|
{
|
|
Scanner Sc = new Scanner (System.in);
|
|
int eingabea = Sc.nextInt();
|
|
int eingabeb = Sc.nextInt();
|
|
|
|
int summe = eingabea + eingabeb;
|
|
System.out.println(summe);
|
|
}
|
|
public static boolean Primzahlen(int n)
|
|
{
|
|
for(int i=2; i< n/2;i++)
|
|
{
|
|
if( n % i == 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
}
|
|
return true;
|
|
}
|
|
public static boolean primzahlDoubletten(int n)
|
|
{
|
|
for(int i=2; i< n/2;i++)
|
|
{
|
|
if( n % i == 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
}
|
|
return true;
|
|
}
|
|
public static int fibo (int n)
|
|
{
|
|
if (n == 1) return 1;
|
|
if (n == 0) return 2;
|
|
|
|
return fibo(n-2) + fibo(n-1);
|
|
}
|
|
public static int binom(int n, int k)
|
|
{
|
|
if (k == 0) return 1;
|
|
if (n == k) return 1;
|
|
|
|
return binom(n-1, k-1) + binom(n-1, k);
|
|
}
|
|
public static void Math()
|
|
{
|
|
double[] arr = new double [10];
|
|
|
|
for( int i=0; i<10;i++)
|
|
{
|
|
arr[i] = Math.random();
|
|
}
|
|
for (int i = 0; i<10; i++)
|
|
{
|
|
System.out.println(arr[i]);
|
|
}
|
|
double summe= 0;
|
|
for(int i=0;i<10;i++)
|
|
{
|
|
summe = summe +arr[i];
|
|
}
|
|
System.out.println("Die Summe aller Zahlen im Array ist " + summe);
|
|
|
|
double min = 1;
|
|
double max = 0;
|
|
|
|
double bisMax = arr[0];
|
|
|
|
for(int i=0; i<arr.length; i++)
|
|
{
|
|
if (arr[i] > bisMax)
|
|
{
|
|
bisMax = arr[i];
|
|
}
|
|
}
|
|
System.out.println("Die größste Zahl des Arrays ist " + bisMax);
|
|
|
|
double bisMin = arr[0];
|
|
|
|
for(int i=0; i<arr.length; i++)
|
|
{
|
|
if (arr[i] < bisMax)
|
|
{
|
|
bisMin = arr[i];
|
|
}
|
|
}
|
|
System.out.println("Die kleinste Zahl des Arrays ist " + bisMin);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|