Java if statements issue [closed] The Next CEO of Stack OverflowIs Java “pass-by-reference” or “pass-by-value”?How do I efficiently iterate over each entry in a Java Map?Does a finally block always get executed in Java?What is the difference between public, protected, package-private and private in Java?Avoiding != null statementsHow do I read / convert an InputStream into a String in Java?When to use LinkedList over ArrayList in Java?How do I generate random integers within a specific range in Java?How do I convert a String to an int in Java?Creating a memory leak with Java

Is there always a complete, orthogonal set of unitary matrices?

Would a grinding machine be a simple and workable propulsion system for an interplanetary spacecraft?

What was the first Unix version to run on a microcomputer?

Is it convenient to ask the journal's editor for two additional days to complete a review?

Won the lottery - how do I keep the money?

I want to delete every two lines after 3rd lines in file contain very large number of lines :

Domestic-to-international connection at Orlando (MCO)

Can we say or write : "No, it'sn't"?

What did we know about the Kessel run before the prequels?

Legal workarounds for testamentary trust perceived as unfair

Do I need to write [sic] when a number is less than 10 but isn't written out?

Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?

Is a distribution that is normal, but highly skewed considered Gaussian?

Calculator final project in Python

Can MTA send mail via a relay without being told so?

RigExpert AA-35 - Interpreting The Information

Make solar eclipses exceedingly rare, but still have new moons

Where do students learn to solve polynomial equations these days?

WOW air has ceased operation, can I get my tickets refunded?

If Nick Fury and Coulson already knew about aliens (Kree and Skrull) why did they wait until Thor's appearance to start making weapons?

How many extra stops do monopods offer for tele photographs?

Why does standard notation not preserve intervals (visually)

What steps are necessary to read a Modern SSD in Medieval Europe?

Why the difference in type-inference over the as-pattern in two similar function definitions?



Java if statements issue [closed]



The Next CEO of Stack OverflowIs Java “pass-by-reference” or “pass-by-value”?How do I efficiently iterate over each entry in a Java Map?Does a finally block always get executed in Java?What is the difference between public, protected, package-private and private in Java?Avoiding != null statementsHow do I read / convert an InputStream into a String in Java?When to use LinkedList over ArrayList in Java?How do I generate random integers within a specific range in Java?How do I convert a String to an int in Java?Creating a memory leak with Java










-3















Old:



if (inv != troll) 
System.out.println("Rock " + a);

if (hañ != troll)
System.out.println("Doll " + b);

if (tall != troll)
System.out.println("Mirror " + c);

if (troll != troll)
System.out.println("Note " + d);

End();
f++;


Updated:



if (!inv.equals(troll)) 
System.out.println("Rock "+ a);
if (!hañ.equals(troll))
System.out.println("Doll "+ b);
if (!tall.equals(troll))
System.out.println("Mirror "+ c);
if (!high.equals(troll))
System.out.println("Note "+ d);
End();
f++;


I am doing a text adventure game and the items belonging in the if statements are arrays, the a b c d are random numbers generated which are sort of a password needed. Right here I am trying to display my inventory, so I want to know if there is any way for the conditions inside the if statement to be displayed as independents. In the sense that if the first is true it displays the first and if the second is not it only displays the ones that are true and then it goes to the method end. The problem I have is that right now all are false, but it still displays all of them except the last one.



I tried adding this in to my code which was given to me in the answers I am sorry I am editing the question its just that i don't know how to comment correctly. Concerning the answer now I am not sure if I am supposed to create a method for equals(); and if so what it should include. But using the updated code it still shows me the array lists even though inv for example has "Rock" inside the array and troll has no words in it.










share|improve this question















closed as unclear what you're asking by Tom, Jacob G., fantaghirocco, Andy Thomas, Book Of Zeus Mar 9 at 7:06


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.













  • 2





    How are the inv and troll variables declared? What is the type, String?

    – Karol Dowbecki
    Mar 8 at 16:15












  • Put some else's in there. if() else if() else if () ...

    – nicomp
    Mar 8 at 16:16







  • 7





    if (troll != troll) ... that doesn't make sense

    – Tom
    Mar 8 at 16:17











  • Yes they are all declared in the class as, List<String> inv = new ArrayList<String>(); List<String> hañ = new ArrayList<String>(); List<String> tall = new ArrayList<String>(); List<String> high = new ArrayList<String>(); List<String> troll = new ArrayList<String>();

    – Alejandro sansour
    Mar 8 at 16:17












  • What I am trying to do is so that if the arrays has somehting inside it displays the value, so I created troll as an extra empty array that has no given value. I don't think this is the best way I just don't know how to do it.

    – Alejandro sansour
    Mar 8 at 16:20















-3















Old:



if (inv != troll) 
System.out.println("Rock " + a);

if (hañ != troll)
System.out.println("Doll " + b);

if (tall != troll)
System.out.println("Mirror " + c);

if (troll != troll)
System.out.println("Note " + d);

End();
f++;


Updated:



if (!inv.equals(troll)) 
System.out.println("Rock "+ a);
if (!hañ.equals(troll))
System.out.println("Doll "+ b);
if (!tall.equals(troll))
System.out.println("Mirror "+ c);
if (!high.equals(troll))
System.out.println("Note "+ d);
End();
f++;


I am doing a text adventure game and the items belonging in the if statements are arrays, the a b c d are random numbers generated which are sort of a password needed. Right here I am trying to display my inventory, so I want to know if there is any way for the conditions inside the if statement to be displayed as independents. In the sense that if the first is true it displays the first and if the second is not it only displays the ones that are true and then it goes to the method end. The problem I have is that right now all are false, but it still displays all of them except the last one.



I tried adding this in to my code which was given to me in the answers I am sorry I am editing the question its just that i don't know how to comment correctly. Concerning the answer now I am not sure if I am supposed to create a method for equals(); and if so what it should include. But using the updated code it still shows me the array lists even though inv for example has "Rock" inside the array and troll has no words in it.










share|improve this question















closed as unclear what you're asking by Tom, Jacob G., fantaghirocco, Andy Thomas, Book Of Zeus Mar 9 at 7:06


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.













  • 2





    How are the inv and troll variables declared? What is the type, String?

    – Karol Dowbecki
    Mar 8 at 16:15












  • Put some else's in there. if() else if() else if () ...

    – nicomp
    Mar 8 at 16:16







  • 7





    if (troll != troll) ... that doesn't make sense

    – Tom
    Mar 8 at 16:17











  • Yes they are all declared in the class as, List<String> inv = new ArrayList<String>(); List<String> hañ = new ArrayList<String>(); List<String> tall = new ArrayList<String>(); List<String> high = new ArrayList<String>(); List<String> troll = new ArrayList<String>();

    – Alejandro sansour
    Mar 8 at 16:17












  • What I am trying to do is so that if the arrays has somehting inside it displays the value, so I created troll as an extra empty array that has no given value. I don't think this is the best way I just don't know how to do it.

    – Alejandro sansour
    Mar 8 at 16:20













-3












-3








-3


1






Old:



if (inv != troll) 
System.out.println("Rock " + a);

if (hañ != troll)
System.out.println("Doll " + b);

if (tall != troll)
System.out.println("Mirror " + c);

if (troll != troll)
System.out.println("Note " + d);

End();
f++;


Updated:



if (!inv.equals(troll)) 
System.out.println("Rock "+ a);
if (!hañ.equals(troll))
System.out.println("Doll "+ b);
if (!tall.equals(troll))
System.out.println("Mirror "+ c);
if (!high.equals(troll))
System.out.println("Note "+ d);
End();
f++;


I am doing a text adventure game and the items belonging in the if statements are arrays, the a b c d are random numbers generated which are sort of a password needed. Right here I am trying to display my inventory, so I want to know if there is any way for the conditions inside the if statement to be displayed as independents. In the sense that if the first is true it displays the first and if the second is not it only displays the ones that are true and then it goes to the method end. The problem I have is that right now all are false, but it still displays all of them except the last one.



I tried adding this in to my code which was given to me in the answers I am sorry I am editing the question its just that i don't know how to comment correctly. Concerning the answer now I am not sure if I am supposed to create a method for equals(); and if so what it should include. But using the updated code it still shows me the array lists even though inv for example has "Rock" inside the array and troll has no words in it.










share|improve this question
















Old:



if (inv != troll) 
System.out.println("Rock " + a);

if (hañ != troll)
System.out.println("Doll " + b);

if (tall != troll)
System.out.println("Mirror " + c);

if (troll != troll)
System.out.println("Note " + d);

End();
f++;


Updated:



if (!inv.equals(troll)) 
System.out.println("Rock "+ a);
if (!hañ.equals(troll))
System.out.println("Doll "+ b);
if (!tall.equals(troll))
System.out.println("Mirror "+ c);
if (!high.equals(troll))
System.out.println("Note "+ d);
End();
f++;


I am doing a text adventure game and the items belonging in the if statements are arrays, the a b c d are random numbers generated which are sort of a password needed. Right here I am trying to display my inventory, so I want to know if there is any way for the conditions inside the if statement to be displayed as independents. In the sense that if the first is true it displays the first and if the second is not it only displays the ones that are true and then it goes to the method end. The problem I have is that right now all are false, but it still displays all of them except the last one.



I tried adding this in to my code which was given to me in the answers I am sorry I am editing the question its just that i don't know how to comment correctly. Concerning the answer now I am not sure if I am supposed to create a method for equals(); and if so what it should include. But using the updated code it still shows me the array lists even though inv for example has "Rock" inside the array and troll has no words in it.







java if-statement






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 20:20









Karol Dowbecki

25.8k93759




25.8k93759










asked Mar 8 at 16:12









Alejandro sansourAlejandro sansour

33




33




closed as unclear what you're asking by Tom, Jacob G., fantaghirocco, Andy Thomas, Book Of Zeus Mar 9 at 7:06


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









closed as unclear what you're asking by Tom, Jacob G., fantaghirocco, Andy Thomas, Book Of Zeus Mar 9 at 7:06


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









  • 2





    How are the inv and troll variables declared? What is the type, String?

    – Karol Dowbecki
    Mar 8 at 16:15












  • Put some else's in there. if() else if() else if () ...

    – nicomp
    Mar 8 at 16:16







  • 7





    if (troll != troll) ... that doesn't make sense

    – Tom
    Mar 8 at 16:17











  • Yes they are all declared in the class as, List<String> inv = new ArrayList<String>(); List<String> hañ = new ArrayList<String>(); List<String> tall = new ArrayList<String>(); List<String> high = new ArrayList<String>(); List<String> troll = new ArrayList<String>();

    – Alejandro sansour
    Mar 8 at 16:17












  • What I am trying to do is so that if the arrays has somehting inside it displays the value, so I created troll as an extra empty array that has no given value. I don't think this is the best way I just don't know how to do it.

    – Alejandro sansour
    Mar 8 at 16:20












  • 2





    How are the inv and troll variables declared? What is the type, String?

    – Karol Dowbecki
    Mar 8 at 16:15












  • Put some else's in there. if() else if() else if () ...

    – nicomp
    Mar 8 at 16:16







  • 7





    if (troll != troll) ... that doesn't make sense

    – Tom
    Mar 8 at 16:17











  • Yes they are all declared in the class as, List<String> inv = new ArrayList<String>(); List<String> hañ = new ArrayList<String>(); List<String> tall = new ArrayList<String>(); List<String> high = new ArrayList<String>(); List<String> troll = new ArrayList<String>();

    – Alejandro sansour
    Mar 8 at 16:17












  • What I am trying to do is so that if the arrays has somehting inside it displays the value, so I created troll as an extra empty array that has no given value. I don't think this is the best way I just don't know how to do it.

    – Alejandro sansour
    Mar 8 at 16:20







2




2





How are the inv and troll variables declared? What is the type, String?

– Karol Dowbecki
Mar 8 at 16:15






How are the inv and troll variables declared? What is the type, String?

– Karol Dowbecki
Mar 8 at 16:15














Put some else's in there. if() else if() else if () ...

– nicomp
Mar 8 at 16:16






Put some else's in there. if() else if() else if () ...

– nicomp
Mar 8 at 16:16





7




7





if (troll != troll) ... that doesn't make sense

– Tom
Mar 8 at 16:17





if (troll != troll) ... that doesn't make sense

– Tom
Mar 8 at 16:17













Yes they are all declared in the class as, List<String> inv = new ArrayList<String>(); List<String> hañ = new ArrayList<String>(); List<String> tall = new ArrayList<String>(); List<String> high = new ArrayList<String>(); List<String> troll = new ArrayList<String>();

– Alejandro sansour
Mar 8 at 16:17






Yes they are all declared in the class as, List<String> inv = new ArrayList<String>(); List<String> hañ = new ArrayList<String>(); List<String> tall = new ArrayList<String>(); List<String> high = new ArrayList<String>(); List<String> troll = new ArrayList<String>();

– Alejandro sansour
Mar 8 at 16:17














What I am trying to do is so that if the arrays has somehting inside it displays the value, so I created troll as an extra empty array that has no given value. I don't think this is the best way I just don't know how to do it.

– Alejandro sansour
Mar 8 at 16:20





What I am trying to do is so that if the arrays has somehting inside it displays the value, so I created troll as an extra empty array that has no given value. I don't think this is the best way I just don't know how to do it.

– Alejandro sansour
Mar 8 at 16:20












2 Answers
2






active

oldest

votes


















1















What I am trying to do is so that if the arrays has somehting inside it displays the value, so I created troll as an extra empty array that has no given value.




To check if the List is empty use isEmpty():



if (!inv.isEmpty()) 







share|improve this answer

























  • This worked perfectly Thank you so much for your helo I appreciate it.

    – Alejandro sansour
    Mar 8 at 16:30


















0















Yes they are all declared in the class as, List inv = new ArrayList(); List hañ = new ArrayList(); List tall = new ArrayList(); List high = new ArrayList(); List troll = new ArrayList();



What I am trying to do is so that if the arrays has somehting inside it displays the value, so I created troll as an extra empty array that has no given value




If you initialize your variable this way and you just want to see if this is empty. you can do:



tall.isEmpty();


to check if it is empty.



But to be honest, this logic is not efficient. it will be better if you just create an object class of inventory with the following as attribute. It will be easier to handle everything.






share|improve this answer





























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1















    What I am trying to do is so that if the arrays has somehting inside it displays the value, so I created troll as an extra empty array that has no given value.




    To check if the List is empty use isEmpty():



    if (!inv.isEmpty()) 







    share|improve this answer

























    • This worked perfectly Thank you so much for your helo I appreciate it.

      – Alejandro sansour
      Mar 8 at 16:30















    1















    What I am trying to do is so that if the arrays has somehting inside it displays the value, so I created troll as an extra empty array that has no given value.




    To check if the List is empty use isEmpty():



    if (!inv.isEmpty()) 







    share|improve this answer

























    • This worked perfectly Thank you so much for your helo I appreciate it.

      – Alejandro sansour
      Mar 8 at 16:30













    1












    1








    1








    What I am trying to do is so that if the arrays has somehting inside it displays the value, so I created troll as an extra empty array that has no given value.




    To check if the List is empty use isEmpty():



    if (!inv.isEmpty()) 







    share|improve this answer
















    What I am trying to do is so that if the arrays has somehting inside it displays the value, so I created troll as an extra empty array that has no given value.




    To check if the List is empty use isEmpty():



    if (!inv.isEmpty()) 








    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Mar 8 at 16:19

























    answered Mar 8 at 16:18









    Karol DowbeckiKarol Dowbecki

    25.8k93759




    25.8k93759












    • This worked perfectly Thank you so much for your helo I appreciate it.

      – Alejandro sansour
      Mar 8 at 16:30

















    • This worked perfectly Thank you so much for your helo I appreciate it.

      – Alejandro sansour
      Mar 8 at 16:30
















    This worked perfectly Thank you so much for your helo I appreciate it.

    – Alejandro sansour
    Mar 8 at 16:30





    This worked perfectly Thank you so much for your helo I appreciate it.

    – Alejandro sansour
    Mar 8 at 16:30













    0















    Yes they are all declared in the class as, List inv = new ArrayList(); List hañ = new ArrayList(); List tall = new ArrayList(); List high = new ArrayList(); List troll = new ArrayList();



    What I am trying to do is so that if the arrays has somehting inside it displays the value, so I created troll as an extra empty array that has no given value




    If you initialize your variable this way and you just want to see if this is empty. you can do:



    tall.isEmpty();


    to check if it is empty.



    But to be honest, this logic is not efficient. it will be better if you just create an object class of inventory with the following as attribute. It will be easier to handle everything.






    share|improve this answer



























      0















      Yes they are all declared in the class as, List inv = new ArrayList(); List hañ = new ArrayList(); List tall = new ArrayList(); List high = new ArrayList(); List troll = new ArrayList();



      What I am trying to do is so that if the arrays has somehting inside it displays the value, so I created troll as an extra empty array that has no given value




      If you initialize your variable this way and you just want to see if this is empty. you can do:



      tall.isEmpty();


      to check if it is empty.



      But to be honest, this logic is not efficient. it will be better if you just create an object class of inventory with the following as attribute. It will be easier to handle everything.






      share|improve this answer

























        0












        0








        0








        Yes they are all declared in the class as, List inv = new ArrayList(); List hañ = new ArrayList(); List tall = new ArrayList(); List high = new ArrayList(); List troll = new ArrayList();



        What I am trying to do is so that if the arrays has somehting inside it displays the value, so I created troll as an extra empty array that has no given value




        If you initialize your variable this way and you just want to see if this is empty. you can do:



        tall.isEmpty();


        to check if it is empty.



        But to be honest, this logic is not efficient. it will be better if you just create an object class of inventory with the following as attribute. It will be easier to handle everything.






        share|improve this answer














        Yes they are all declared in the class as, List inv = new ArrayList(); List hañ = new ArrayList(); List tall = new ArrayList(); List high = new ArrayList(); List troll = new ArrayList();



        What I am trying to do is so that if the arrays has somehting inside it displays the value, so I created troll as an extra empty array that has no given value




        If you initialize your variable this way and you just want to see if this is empty. you can do:



        tall.isEmpty();


        to check if it is empty.



        But to be honest, this logic is not efficient. it will be better if you just create an object class of inventory with the following as attribute. It will be easier to handle everything.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 8 at 16:39









        SemjeromeSemjerome

        236




        236













            Popular posts from this blog

            Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

            Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

            2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived