Practice problem with arrays issue

/*program asks the user to use specific keys to unlock specific keys, if the wrong key is used on the wrong key it explodes and ends the program */ import java.util.Scanner; public class Keygame { public static void main(String[] args){ Scanner input = new Scanner(System.in); String[] key = {"Skeleton key", "Stone key", "Wood key", "plastic key" }; System.out.println("Before you are 4 keys. \n Each key take a different key. \n You have each key in your bag but be careful. \n Using the wrong key will cause the key to explode.\n"); System.out.println("please type a number corresponding to the one beside each key \n"); for(int i = 0; i < key.length; i++){ System.out.println(i+1 + "." + key[i]); } int pkey = input.nextInt(); if(pkey >= 1 && pkey <= key.length){ int chosenkey = pkey - 1; System.out.println(" you chose " + key[chosenkey]); } else{ System.out.println("You have chosen the (INSTANT DEATH IF YOU CHOOSE IT key) \n you will now instantly die \n game over "); } String[] door = {"Skeleton door", "Stone door", "Wood door", "plastic door" }; System.out.println("\nplease type a number corresponding to the one beside each door"); for(int i = 0; i < door.length; i++){ System.out.println(i+1 + "." + door[i]); } int pdoor = input.nextInt(); if(pdoor >= 1 && pdoor <= door.length){ int chosendoor = pdoor - 1; System.out.println(" you chose " + door[chosendoor]); } else{ System.out.println("You have chosen the (INSTANT DEATH IF YOU CHOOSE IT key) \n you will now instantly die \n game over "); } // print out what key and door you have chosen System.out.println("you are unlocking the " + door + " with " + key); } } cant seem to figure out how to print out the arrays the user chooses, no matter what i do it either prints out the number of the array or the memory address.
4 Replies
JavaBot
JavaBot9mo ago
This post has been reserved for your question.
Hey @stapps! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
stapps
stappsOP9mo ago
it worked, thx man
JavaBot
JavaBot9mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server