-6

How do I replace the number that the user inputs as their choice with the actual corresponding string that their choice means in the print line.

import java.util.Scanner; 

public class MagicGame
{
  public static void main(String [] args)

  {

    String name;
    int userCharacter;
    int armorChoice;
    int weaponChoice;


    Scanner input = new Scanner(System.in); 

    System.out.println("Please enter your name");
    name = input.nextLine();
    { 
    System.out.println("Please select the character you would like to play:" + '\n' + "1 for Magic User" + '\n' + "2 for Fighter" + '\n' + "3 for Thief" + '\n' + "4 for Druid" );
    userCharacter = input.nextInt();

    System.out.println("Please select your Armor Type:" + '\n' + "1 for Steel plate – Armor Class 10" + '\n' + "2 for Chain mail – Armor Class 5" + '\n' + "3 for Leather armor – Armor Class 3" + '\n' + "4 for A robe – Armor Class 1");
    armorChoice = input.nextInt();

    System.out.println("Please choose a Weapon:" + '\n' + "1 for Sword" + '\n' + "2 for Short Sword" + '\n' + "3 for Scimitar" + '\n' + "4 for Dagger");
    weaponChoice = input.nextInt();


    System.out.println("Hello " + name + "! You chose to play a " + userCharacter + "." + '\n' + "Your armor is" + armorChoice + "." + '\n' + "You will be fighting with a " + weaponChoice + ".");
  }
}

It is longer but I had to trim it down.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
John
  • 31
  • 4

1 Answers1

0

Which programming language?

Java:

String s = String.valueOf(123);
String s = 123 + "";

C++

int a = 10;
stringstream ss;
ss << a;
string str = ss.str();

C++0x

std::string s = std::to_string(42);

C#

string s = myInt.ToString();
Cem Catikkas
  • 7,171
  • 4
  • 29
  • 33
Mosa
  • 373
  • 1
  • 14
  • ok, here is my code https://gist.github.com/anonymous/a896b9f3ea0ba7449b25 i need to replace the number with the corresponding string in the print line – John Oct 18 '14 at 21:44
  • 3
    use that as a question. Your original question is awful. – tom Oct 18 '14 at 21:45