Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /*
- * Create by Arthur, Dennis, Dimitri
- */
- public class PathNodes{
- private static int xz; //Ziel in x Koordinate
- private static int yz; //Ziel in y Koordinate
- private static int x; //Start in x Koordinate
- private static int y; //Start in y Koordinate
- private static int counter; //Zähler für die Pfade
- public static void main(String[] args) {
- //Scanner sc = new Scanner(System.in); //ermöglicht Eingabe
- //System.out.print("Bitte eine Zahl eingeben (> 0)" + ": "); //Test zum eingeben
- //int eingabe = sc.nextInt(); //scannt den Eingabewert
- //if (eingabe > 0) {//Wenn Eingabe größer als 0 erfolgt
- xz = 1;//eingabe; //Ziel
- yz = 1;//eingabe; //Ziel
- x = 0; //Start
- y = 0; //Start
- counter = 0;//Zähler
- search();
- // } else {//kleinere Zahl eingegeben als Erlaubt
- // System.out.println("Wups, da gab es wohl einen kleinen Fehler in der Eingabe. Bitte nochmals versuchen!");
- }
- // }
- public static void right() {//Schritt nach oben!
- x = x + 1;
- counter = counter + 1;
- }
- public static void rightup() {//Schritt nach obenrechts!
- x = x + 1;
- y = y + 1;
- counter = counter + 1;
- }
- public static void rightdown() {//Schritt nach rechtsunten!
- x = x + 1;
- y = y - 1;
- counter = counter + 1;
- }
- public static void up() {//Schritt nach oben!
- y = y + 1;
- counter = counter + 1;
- }
- public static void upleft() {//Schritt nach obenlinks
- x = x - 1;
- y = y + 1;
- counter = counter + 1;
- }
- public static void sRight() {//Schritt nach oben! Startpunkt!!
- x = x + 1;
- counter = counter + 2;
- }
- public static void sRightup() {//Schritt nach obenrechts! Startpunkt!!
- x = x + 1;
- y = y + 1;
- counter = counter + 2;
- }
- public static void sUp() {//Schritt nach oben! Startpunkt!!
- y = y + 1;
- counter = counter + 2;
- }
- public static void search() {
- boolean direkt = true;
- boolean oben = true;
- boolean rechts = true;
- if (direkt) {//der direkte Weg (zu Erst)
- for (int i = 0; i < xz; i++) {
- sRightup();
- }
- if (x == xz && y == yz) {
- direkt = false;
- x=0;
- y=0;
- }
- }
- if (oben) {//Weg nach oben (zweiter Weg)
- boolean upup = true;
- boolean updown = true;
- if (upup) {
- for (int i = 0; i < yz; i++) {
- sUp();
- }
- }
- if (x < xz && y == yz) {
- for (int i = 0; i < yz; i++) {
- up();
- }
- }
- if (x < xz && y > yz){
- for (int ii = 0; ii < yz; ii++){
- rightdown();
- }
- }
- if (x == xz && y == yz) {
- upup = false;
- x = 0;
- y = 0;
- }
- if (updown) {//Weg nach oben und dann unten!
- for (int i = 0; i < xz; i++)
- sUp();
- if (x < xz && y == yz) {
- for (int i = 0; i < xz; i++) {
- rightdown();
- }
- }
- if (x == xz && y < yz) {
- for (int ii = 0; ii < xz; ii++) {
- right();
- }
- }
- if (x > xz && y < yz) {
- for (int iii = 0; iii < xz; iii++) {
- upleft();
- }
- }
- if(x == xz && y == yz){
- updown = false;
- oben = false;
- x=0;
- y=0;
- }
- }
- }
- if(rechts) {//dritter Weg
- boolean rightright = true;
- boolean rightup = true;
- if (rightright) {//Der Weg nach rechts
- for (int i = 0; i < xz; i++) {
- sRight();
- }
- if (x == xz && y < yz) {
- for (int ii = 0; ii < xz; ii++) {
- right();
- }
- }
- if (x > xz && y < yz) {
- for (int iii = 0; iii < xz; iii++) {
- upleft();
- }
- }
- if(x ==xz && y == yz){
- rightright = false;
- x=0;
- y=0;
- }
- }
- if(rightup){//Der Weg nach rechts und dann oben
- for(int i = 0;i<xz;i++){
- sRight();
- }
- if(x == xz && y < yz){
- for(int ii = 0;ii<yz;ii++){
- upleft();
- }
- }
- if(x < xz && y ==yz){
- for(int iii =0; iii<yz;iii++){
- up();
- }
- }
- if(x < xz && y > yz){
- for(int iiii=0; iiii<yz;iiii++){
- rightdown();
- }
- }
- if(x ==xz && y == yz){
- rightup = false;
- rechts = false;
- x = 0;
- y = 0;
- }
- }
- }
- System.out.println("Es gab genau " +counter+ " Pfade");
- }//end search()
- }//end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement