I am trying to make the while loop stop asking for user input once the user enters &quot;stop&quot;, but i cannot get it to stop asking the user for input. public static void main(String[] args) {     exampletoday llist=new exampletoday();     Scanner keyboard=new Scanner(System.in);     System.out.println(&quot;Enter the first operator or operand: &quot;);     String first=keyboard.nextLine();     llist.addNode(first);     while(true)     {     System.out.println(&quot;Enter the next operand or operator or stop to stop: &quot;);     String next=keyboard.nextLine();     llist.addNode(next);     if(next==&quot;stop&quot;)     break; }
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?
4602
Example (note the case):  string s = "Hello world!"; String s = "Hello world!";   What are the guidelines for the use of each? And what are the differences?
118126
G'day all,   I have a console project where it is intended the user presses the keyboard direction keys (non-numeric keypad) to move an avatar. I am having difficulty coding to check for the press of these keys. In Pascal it was easy enough to use "readkey" and code, for example, for #80 for the down keypress. However, I am stumped how to implement the same functionality in Java, though I think I understand the use of System.in and BufferedInputStream.  Could anyone help me out? Your thoughts or hints are much appreciated.
102259
I need to search a string in the string array. I dont want to use any for looping in it  string [] arr = {"One","Two","Three"};  string theString = "One"   I need to check whether theString variable is present in arr.
27214
How can I return to the start of a line and overwrite what has already been output on the console? The following does not appear to work:  System.out.print(mystuff+'\r');
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?
78122
Please take a look on the following pseudo-code:  boolean blocked[2]; int turn; void P(int id) {       while(true) {              blocked[id] = true;              while(turn != id) {                     while(blocked[1-id])                     /* do nothing */;                     turn = id;              }              /* critical section */              blocked[id] = false;              /* remainder */       } } void main() {       blocked[0] = false;       blocked[1] = false;       turn = 0;       parbegin(P(0), P(1)); //RUN P0 and P1 parallel }   I thought that a could implement a simple Mutual - Exclution solution using the code above. But it's not working. Has anyone got an idea why?  Any help would really be appreciated!
81621
If I write the following class:  public class Example {        int j;       int k;        public Example(int j, int k) {            j = j;            k = k;       }        public static void main(String[] args) {            Example exm = new Example(1,2);            System.out.println(exm.j);            System.out.println(exm.k);       }  }   The program compiles, but when I run the program, the main method will print out two 0s. I know that in order to say that I want to initialize the instance variables in the constructor I have to write:  this.j = j; this.k = k;   But if I don't write it, then which variable is evaluated (or considered) in the constructor (on the left and on the write hand side of the expressions)? Is is the argument or the instance variable? Does it make a difference?  Are there other cases where the use of this is obligatory?
10136
How can I validate the user input by using scanf. Right now I have something like this, but doesn't work.  NOTE: I have the atoi just to validate that the scanf validation works.  scanf("%[0987654321.-]s",buf);  i = atoi(buf);  if(i)     index = i;
74382
i have:  for i in range(2,n):     if(something):        do something     else:        do something else        i = 2 **restart the loop   But that doesn't seem to work. Is there a way to restart that loop?   Thanks
108487
I have the code below (I've included what I believe are all relevant sections):  private String readCommand = "SELECT LEVEL FROM USERS WHERE VAL_1 = ? AND VAL_@ = ?;"; public bool read(string id) {     level = -1;     MySqlCommand m = new MySqlCommand(readCommand);     m.Parameters.Add(new MySqlParameter("", val1));     m.Parameters.Add(new MySqlParameter("", val2));     MySqlDataReader r = m.ExecuteReader();     if (r.HasRows)         level = Convert.ToInt32(r.GetValue(0).ToString());     r.Close();     return true; }   When I run this, I get an IndexOutOfBoundsException on adding the first parameter. What have I done wrong?
92333
if ('text'.equals(str))   or   if ('text' == str)   Is there any difference? If yes, then what is it?   Added, after answered.  String q = 'teXt'; system.debug('teXt'.equals(q)); // true system.debug('teXt' == q);      // true system.debug('text'.equals(q)); // false system.debug('text' == q);      // true
40938
After I posted this question, I found a similar post that seemed to answer it: . I'll leave this in place for now, as I am not sure how to mark my own question as a duplicate  In attempting to debug a SOQL query error, I encountered a strange behavior with Database.query and bind variables. Specifically, when I run this code:  String userQuery = 'SELECT Id FROM User'; if (true) {     List&lt;String&gt; firstNames = new List&lt;String&gt;{'James','Joe'};     userQuery += ' WHERE FirstName IN :firstNames'; } Database.query(userQuery);   the Database.query statement executes with no errors, despite the fact that the variable firstNames does not exist in its context. However, when I add an else clause:  String userQuery = 'SELECT Id FROM User'; if (true) {     List&lt;String&gt; firstNames = new List&lt;String&gt;{'James','Joe'};     userQuery += ' WHERE FirstName IN :firstNames'; } else {     List&lt;String&gt; firstNames; } Database.query(userQuery);   I receive a null object reference exception. It seems like Salesforce is checking to see if the variable is only declared once beforehand and, if so, uses its value in the context it was declared. This seems strange to me, so I was wondering if anybody here has any insight into what is going on under the hood.
79088
I am writing a batch file to execute some other programs. In this case I need to prompt for a password. Do I have any way to mask the input text? I don't need to print ******* characters instead of input characters. Linux's Password prompt behavior (Print nothing while typing) is enough.     @echo off SET /P variable=Password :  echo %variable% Pause   This will read the input but I can't mask the text using this approach.
47899
Semantically, the Yes/No buttons are roughly equivalent to the Ok/Cancel buttons, but in general what would you recommend to use? Should I always use Yes/No or always use Ok/Cancel? Or does it depend on the case?
108847
If I type ' (single quote, next to the &lt;enter&gt; button) in the terminal and then press enter it drops to a &gt; prompt.  What exactly is this, what's it used for, and what type of commands can I enter here?    I can &lt;Ctrl-C&gt; out of it but that's all I got.
9698
I'm trying to write a program in C (on Linux) that loops until the user presses a key, but shouldn't require a keypress to continue each loop.  Is there a simple way to do this? I figure I could possibly do it with select() but that seems like a lot of work.  Alternatively, is there a way to catch a ctrl-c keypress to do cleanup before the program closes instead of non-blocking io?