The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
untitled Java Code
Posted by: ggT | December 7, 2010 @ 2:50pm
Java Code
[
Download
]
package infoHaF.exercise7; import java.util.Scanner; public class Euklid { public static void main(String[] args) { int j = 1 ; System.out.print("Defnieren Sie a: "); Scanner ascanner = new Scanner (System.in); int a = ascanner.nextInt(); System.out.print("Defnieren Sie b: "); Scanner bscanner = new Scanner (System.in); int b = bscanner.nextInt(); // jetzt sehr unst�ndlich weil ich versucht habe den Zero Fehler weg zu bekommen // Check ob eine odere mehrere Var = 0 sind while ( b != 0 && a != 0 && j <= 1) { int gcd = ggT(Math.abs(a), Math.abs(b)); System.out.println("ggT: " + gcd); j++; } while (a == 0 && b == 0 && j <= 1){ System.out.println ("ggT nicht definiert!" ); j++; } while ( b == 0 && j <= 1 ) { System.out.print("ggT: " + a); j++; } while ( a == 0 && j <= 1 ){ System.out.println("ggT: " + b); j ++; } } public static int ggT(int a, int b) { int quo; int rest = 0; // Fall a > b if (a > b) { quo = a / b; rest = a % b; while (rest > 0){ //while loop bis ggT gefunden wurde a = b; b = rest; quo = a / b; rest = a % b; } return b; } // Fall a < b else { int space = b; b = a; // Variablen-Tausch von a und b a = space; quo = a / b; rest = a % b; while (rest > 0){ a = b; b = rest; quo = a / b; rest = a % b; } } return b; } }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.53 / 8
45 Votes