I currently have a game where the user needs to type in the secret code correctly to play the game. However, each time I type in "game" as the user code, it prints out Goodbye!, rather than play the game. Can someone explain why?     public static void secretCode() {       System.out.println("Enter your secret code to play: ");       Scanner passwordInput = new Scanner(System.in);       String userCode = passwordInput.nextLine();       String gameCode = "game";      if (userCode == gameCode) {         System.out.println("Let's begin! Each game costs $50 to play.");         playGame();         System.out.println("Thanks for playing. Goodbye!");     }     if (userCode != gameCode) {         System.out.println("Goodbye!");     }  }
93
I've been using the == operator in my program to compare all my strings so far. However, I ran into a bug, changed one of them into .equals() instead, and it fixed the bug.  Is == bad? When should it and should it not be used? What's the difference?
69342
I'm using this code to let the user enter in names while the program stores them in an array until they enter an empty string (they must press enter after each name):  people = [] info = 'a' # must fill variable with something, otherwise loop won't execute  while not info.empty?     info = gets.chomp     people += [Person.new(info)] if not info.empty? end   This code would look much nicer in a do ... while loop:  people = []  do     info = gets.chomp     people += [Person.new(info)] if not info.empty? while not info.empty?   In this code I don't have to assign info to some random string.  Unfortunately this type of loop doesn't seem to exist in Ruby. Can anybody suggest a better way of doing this?
89624
I've been reading . Apparently I would gain root access if I hold down enter (somewhere) for 70 seconds. I tried it on a password prompt but it gave me like 3 attempts and stopped. I tried it on a tty but it didn't work also. Am I not vulnerable or am I doing it wrong?
23909
Looking for reviewers to suggest optimization and improvements, and to evaluate coding practices.  final class Variables {     private final int x;     private final int y;      Variables(int x2, int y2) {         this.x = x2;         this.y = y2;     }      public int getX() {         return x;     }      public int getY() {         return y;     }      @Override public String toString()  {          return "x = " + x + " y = " + y;     } }  public final class FindMissing {      private FindMissing() {};      /**  * Takes an input a sorted array with two variables that repeat in the  * range. Remaining variable are consecutive. and returns two variables that repeats  *   * eg: for a range of 1,2,3,4, a valid input is [1, 4], [1, 3] etc.  *   * @param a : the sorted array.  */ /*  * Why is start needed ?  * If start is not given then if a1 is empty how do we know if missing numbers were  * [1, 2] or [4, 5] ??.   */ public static Variables sortedConsecutiveTwoMissing (int[] a, int startOfRange) {     if (a == null) throw new NullPointerException("a1 cannot be null. ");      int low = startOfRange;     // calculating the highest value of the range. it needs to be 2 more than length since all elememts are consecutive.     int high = startOfRange + (a.length - 1) + 2;      int i = 0;     boolean foundX = false;     int x = 0;       while (i &lt; a.length) {         if (a[i] != low) {             if (foundX) {                 return new Variables(x, low);             } else {                 x = low;                 foundX = true;             }         } else {             i++;         }         low++;     }      return new Variables(x, high);  }  public static void main(String[] args) {         // unsortedConsecutiveTwoMissing         int[] a6 = {1, 4};         System.out.println("Expected 2 and 3, Actual " + sortedConsecutiveTwoMissing(a6, 1));         // unsortedConsecutiveTwoMissing         int[] a7 = {-4, -1};         System.out.println("Expected -3 and -2, Actual " + sortedConsecutiveTwoMissing(a7, -4));         int[] a8 = {-4, -3, -2, -1};         System.out.println("Expected 0 and 1, Actual " + sortedConsecutiveTwoMissing(a8, -4));         int[] a9 = {5};         System.out.println("Expected 4 and 6, Actual " + sortedConsecutiveTwoMissing(a9, 4));         }      }
47989
Okay, we know that the following two lines are equivalent -    (0 == i) (i == 0)   Also, the first method was encouraged in the past because that would have allowed the compiler to give an error message if you accidentally used '=' instead of '=='.  My question is - in today's generation of pretty slick IDE's and intelligent compilers, do you still recommend the first method?    In particular, this question popped into my mind when I saw the following code -   if(DialogResult.OK == MessageBox.Show("Message")) ...    In my opinion, I would never recommend the above. Any second opinions?
82090
int i = 4; string text = "Player "; cout &lt;&lt; (text + i);   I'd like it to print Player 4.  The above is obviously wrong but it shows what I'm trying to do here. Is there an easy way to do this or do I have to start adding new includes?
98178
key__c :- abcdefghijklmnop  public static String decrypt(String data) {     EncryptionSettings__c settings = EncryptionSettings__c.getOrgDefaults();     if (settings.key__c == null) {         throw new FacebookException('Cannot decrypt without a key!');     }     Blob key = EncodingUtil.base64Decode(settings.key__c);     return Crypto.decryptWithManagedIV('AES128', key, EncodingUtil.base64Decode(data)).toString(); }  public static String encrypt(String data) {         EncryptionSettings__c settings = EncryptionSettings__c.getOrgDefaults();     Blob key = null;     if (settings.key__c == null) {         checkUserCanCustomizeApplication();         key = Crypto.generateAesKey(128);         settings.key__c = EncodingUtil.base64Encode(key);         insert settings;     } else {         key = EncodingUtil.base64Decode(settings.key__c);     }     return EncodingUtil.base64Encode(Crypto.encryptWithManagedIV('AES128', key, Blob.valueOf(data))); }
43114
Whenever I'm at the console login, I press up arrow intentionally to see the previously typed commands. But I see this ^[[A.  But when I press Ctrl Alt Print Screen Scroll Lock Pause Break Page Up Page Down Win keys doesn't echo any characters.  What might be the reason behind?  Does ^[[A sort of characters imply anything?
56649
Wow, I've really done it this time. I've locked myself out of my machine.  In preparing for a Cherokee language course, I added the Cherokee keyboard layout to my options. However, I was unable to generate any Cherokee characters by selecting that input device.  I found an article on the web which instructed me to use the dpkg-reconfigure keyboard-configuration command in a terminal.  Once I did that, I rebooted as instructed. Once I was presented with the login screen, I entered my password as usual only for it to fail.  After failing a few times, I gave my attention to what is usually a mundane exercise (i.e., logging in).  While I carefully entered my password, each time, I get the message, "Sorry that didn't work..."  So, I brought up the onscreen keyboard... But the password box displays an asterisk for only the first character of my password.  I attempted to use the direct Unicode input method (ctrl-shift-Uxxxx) but the Cherokee keyboard has no "U" key.  Can anyone please help me troubleshoot this?
11109
I've been having a lot of problems trying to figure out how to use scanf().  It seems to work fine with integers, being fairly straight forward scanf("%d", &amp;i).  Where I am running into issues is using scanf() in loops trying to read input.  For example:  do {   printf("counter: %d: ", counter);   scanf("%c %c%d", &amp;command, &amp;prefix, &amp;input); } while (command != 'q');    When I enter in a validly structured input like c P101, it seems to loop again before prompting me.  This seems to happen even with a single:  scanf("%c", &amp;c)    in a while loop.  It'll do the loop twice before prompting me again.  What is making it loop twice, and how do I stop it? When I enter in less amount of input that programmatically wouldn't have another character or number such as q, pressing enter seems to prompt me to enter more.  How do I get scanf() to process both single and double character entries?
11438
Suppose I press the A key in a text editor and this inserts the character a in the document and displays it on the screen. I know the editor application isn't directly communicating with the hardware (there's a kernel and stuff in between), so what is going on inside my computer?
92088
public class WrapperTest {      public static void main(String[] args) {          Integer i = 100;         Integer j = 100;          if(i == j)             System.out.println("same");         else             System.out.println("not same");     }     }   The above code gives the output of same when run, however if we change the value of i and j to 1000 the output changes to not same. As I'm preparing for SCJP, need to get the concept behind this clear. Can someone explain this behavior.Thanks.
121
I always thought Java uses pass-by-reference. However, I've seen a couple of blog posts (for example, ) that claim that it isn't (the blog post says that Java uses pass-by-value). I don't think I understand the distinction they're making. What is the explanation?
2156
In Java is there a way to check the condition:  "Does this single character appear at all in string x"  without using a loop?
80287
I know what    program &gt; /dev/null 2&gt;&amp;1    does. It redirects the output to /dev/null and 2&gt;&amp;1 means to redirect the error output in the same place where the output is sent.  My problem is I always have to google it because I never remember it.  So, I try &amp;2&gt;1, 1&gt;2&amp;, 1&gt;&amp;2... I try every combination until I google it...  What's the trick to remember it easily?
14721
I'm using MonoDevelop to write C# (.NET) codes, on Ubuntu Desktop 14.0.5 LTS. While testing a simple Hello World code, I encountered a problem - earlier on windows, I used the Console.ReadKey() statement to make sure that the console doesn't disappear instantaneously after showing the output. However, this trick is not working on Ubuntu. Here's the code, in case you'd need to see it:  using System;  namespace Project_1 {     class MainClass {         public static void Main (string[] args) {             Console.WriteLine ("Hello World!");             Console.ReadKey ();         }     } }   In spite of the last statement, the console shows up for about 1/100th of a second before disappearing. Precisely, the Console.ReadKey() statement is being ignored(??). I have no idea why this is happening. I'm new to using Ubuntu and installed MonoDevelop a few hours ago.  How do I fix this issue?
76533
The current top-voted to  states:     Another one that's not so much a security issue, although it is security-related, is complete and abject failure to grok the difference between hashing a password and encrypting it. Most commonly found in code where the programmer is trying to provide unsafe "Remind me of my password" functionality.   What exactly is this difference? I was always under the impression that hashing was a form of encryption. What is the unsafe functionality the poster is referring to?