mercredi 2 août 2017

Why do I get more than one answer for something

I want to know why I get this:

team1: Blue
team2: Orange
team3: Purple
team4: Blue

As you can see, I get 2 Blues, any way I can fix this or is this just how it is? Any good question titles will be accepted.
If it helps, here is my code:

import java.util.Random;

public class randoma {
  public static void main(String[] args) {
    Random as = new Random();
    int Purple = 1;
    int Orange = 2;
    int Red;
    Red = as.nextInt(6);
    int Green;
    Green = as.nextInt(6);
    int Blue;
    Blue = as.nextInt(6);
    int Yellow;
    Yellow = as.nextInt(6);
    int sub;
    sub = as.nextInt(6);
    if (2 >= sub) {
      sub = sub + 2;
    } else if (sub >= 4) {
      sub = sub - 2;
    } else {
      sub = sub;
    }
    if (2 >= Red) {
      Red = Red + sub;
    } else {
      Red = Red;
    }
    if (2 >= Green) {
      Green = Green + sub;
    } else {
      Green = Green;
    }
    if (2 >= Blue) {
      Blue = Blue + sub;
    } else {
      Blue = Blue;
    }
    if (2 >= Yellow) {
      Yellow = Yellow + sub;
    } else {
      Yellow = Yellow;
    }
    if (Red == Green) {
      Red = Red - sub;
    } else {
      Red = Red;
    }
    if (Red == Blue) {
      Red = Red - sub;
    } else {
      Red = Red;
    }
    if (Red == Yellow) {
      Red = Red - sub;
    } else {
      Red = Red;
    }
    if (Green == Blue) {
      Green = Green - sub;
    } else {
      Green = Green;
    }
    if (Green == Yellow) {
      Green = Green - sub;
    } else {
      Green = Green;
    }
    if (Blue == Yellow) {
      Blue = Blue - sub;
    } else {
      Blue = Blue;
    }
    String[] teams = {"Red", "Green", "Blue", "Yellow", "Orange", "Purple"};
    System.out.println("team1: " + teams[Green]);
    System.out.println("team2: " + teams[Blue]);
    System.out.println("team3: " + teams[Yellow]);
    System.out.println("team4: " + teams[Red]);
 }
}

Any help is appreciated and if it helps, please copy and paste the code here to play around: http://www.browxy.com/. I have been trying for a while and have no solution.




Aucun commentaire:

Enregistrer un commentaire