samedi 29 juillet 2017

How do I make an int have a String's value or is it possible (in java)

I have a good amount of code and it makes it so that you randomly are assigned a team, but right now my compiler comes out with the number of the team, not the team name. Is there any way I can change this?
My code:

import java.util.Random;

public class Game {
public static void main(String[] args) {
Random m = new Random();
int b;
b = m.nextInt(12);
if (b >= 6) {
  b = b;
} else {
  b = b + 6;
}
int a = b;
int playerAmount = a;
int c = playerAmount - 1;
System.out.println("Amount of Players going up against you: " + c);
int teama;
teama = m.nextInt(2);
int teamb;
teamb = m.nextInt(2);
if (teama == 0) {
  teama = teama + 1;
}  else if (teamb == teama) {
  teamb = teamb - 1;
}  else if (teamb == 0) {
  teamb = teamb + 1;
}  else if (teamb == teama) {
  teamb = teamb - 1;
} else {
  teamb = teamb;
}
System.out.println("Teama: " + teama);
System.out.println("Teamb: " + teamb);
int player;
player = m.nextInt(2);
if (player == teama) {
  player = teama;
} else {
  player = teamb;
}
if (player == 0) {
  player = "teamb";
} else {
  player = "teama";
}
System.out.println("You are on: " + player);
}
}

And then what I come out with: Amount of Players going up against you: 6 Teama: 1 Teamb: 0 You are on: 1 Is there even a way to make the teams have names or do I just have to stay like this?
BTW: I have searched for a while and haven't found anything that works.




Aucun commentaire:

Enregistrer un commentaire