My Code may look grammatically awful, but that's because I've had to censor out foul language.  I'm trying to get it to terminate when someone enters "bats", "Bats", or "BATS".  import java.util.*;  public class BATS {      public static void main(String[] args)     {      Scanner BAT = new Scanner(System.in);     String Bat, BATS;     System.out.println("What is the most badass flying mammal ever?!");      Bat = BAT.nextLine();     Bat = Bat.toUpperCase();          while(Bat != "BATS")         {              System.out.println("No, its BATS!!!!!!!!!! Try again.");             Bat = BAT.nextLine();             Bat = Bat.toUpperCase();             if(Bat == "BATS")             {             System.out.println("YOU'RE  RIGHT THEY ARE !!!!!");             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?
65647
Pattern pattern = Pattern.compile("^[a-z]+$"); String string = "abc-def"; assertTrue( pattern.matcher(string).matches() ); // obviously fails   Is it possible to have the character class match a "-" ?
47354
This code fails with Emergency stop:  \documentclass{scrbook} \usepackage{listings} \newcommand{\demo}{% \begin{lstlisting} foobar \end{lstlisting} }  \begin{document} \demo \end{document}   Why?
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?
2897
Today, I was caught redhanded while attempting to code golf a password generator for Twitter.  import string as s,random;print ''.join(random.sample(s.letters+s.digits+s.punctuation,9))   90 chars. Since that is a lot of spare space, I decided to raise the bar and make it executable too.  echo -e "#!/usr/bin/python\nimport string as s,random;print ''.join(random.sample(s.letters+s.digits+s.punctuation,9))"&gt;pg;chmod +x pg;./pg   139 chars. Nice, except obviously bash chokes on the exclamation point.  badp@delta:~$ echo -e "#!/usr/bin/python\nimport string as s,random;print ''.join(random.sample(s.letters+s.digits+s.punctuation,9))"&gt;pg;chmod +x pg;./pg bash: !/usr/bin/python\nimport: event not found   Pesky exclamation point. "Let's escape it," I thought! I do have one spare character after all.  echo -e "#\!/usr/bin/python\nimport string as s,random;print ''.join(random.sample(s.letters+s.digits+s.punctuation,9))"&gt;pg;chmod +x pg;./pg   Obviously...  badp@delta:~$ echo -e "#\!/usr/bin/python\nimport string as s,random;print ''.join(random.sample(s.letters+s.digits+s.punctuation,9))"&gt;pg;chmod +x pg;./pg ./pg: line 2: syntax error near unexpected token `(' ./pg: line 2: `import string as s,random;print ''.join(random.sample(s.letters+s.digits+s.punctuation,9))' badp@delta:~$ cat pg #\!/usr/bin/python import string as s,random;print ''.join(random.sample(s.letters+s.digits+s.punctuation,9))   Leaving my asinine code golfing aside -- I can't explain this.  With \!, the exclamation point was escaped, except it really wasn't, because the \! was left as-is for echo to pick up.  One solution could have been using \x21 instead, but I'm not convinced that's the proper way of escaping an exclamation point in a bash command.  tl;dr: How do you properly escape an exclamation point in a bash command?
14731
It is much more convenient and cleaner to use a single statement like  import java.awt.*;   than to import a bunch of individual classes  import java.awt.Panel; import java.awt.Graphics; import java.awt.Canvas; ...   What is wrong with using a wildcard in the import statement?
26226
I need a robust and simple way to remove illegal path and file characters from a simple string. I've used the below code but it doesn't seem to do anything, what am I missing?  using System; using System.IO;  namespace ConsoleApplication1 {     class Program     {         static void Main(string[] args)         {             string illegal = "\"M&lt;&gt;\"\\a/ry/ h**ad:&gt;&gt; a\\/:*?\"&lt;&gt;| li*tt|le|| la\"mb.?";              illegal = illegal.Trim(Path.GetInvalidFileNameChars());             illegal = illegal.Trim(Path.GetInvalidPathChars());              Console.WriteLine(illegal);             Console.ReadLine();         }     } }
31776
In sh (not Bash), how would we abort execution of command when the prompt is in &gt; mode?  For example, when entering a string with quotes only at the beginning, it makes the prompt look like &gt;, without the ability to quit it normally, unless hitting Ctrl + D. Example:  root@MyPC:~# echo "hello &gt; I am &gt; (How do I exit of this mode?)   In case that I don't know which character delimits the string (" or ' or simply escaping a newline/spaces with backslash), is there a way to let Bash know that I want to abort the execution of the current command?
11190
When building console applications that take parameters, you can use the arguments passed to Main(string[] args).   In the past I've simply indexed/looped that array and done a few regular expressions to extract the values. However, when the commands get more complicated, the parsing can get pretty ugly.    So I'm interested in:   Libraries that you use Patterns that you use   Assume the commands always adhere to common standards such as .
13420
What's the difference between \n and \r (I know it has something to do with OS), and what's the best way to echo a line break that will work cross platform?  EDIT: In response to Jarod, I'll be using ths to echo a line break in a .txt log file, though I'm sure I'll be using it in the future for things such as echoing HTML makup onto a page.
85770
I just spotted someone use \newcommand* in an answer and realised that I'd never quite sorted out in my head what the star (asterisk) was there for.  (This one is practically impossible to search for on the internet so this is a good place to record the answer!)
4322
I have a long line of code that I want to break up among multiple lines. What do I use and what is the syntax?  For example, adding a bunch of strings,  e = 'a' + 'b' + 'c' + 'd'   and have it in two lines like this:  e = 'a' + 'b' +     'c' + 'd'
58461
Consider the code:  PreparedStatement ps = null; ResultSet rs = null; try {   ps = conn.createStatement(myQueryString);   rs = ps.executeQuery();   // process the results... } catch (java.sql.SQLException e) {   log.error("an error!", e);   throw new MyAppException("I'm sorry. Your query did not work."); } finally {   ps.close();   rs.close(); }   The above does not compile, because both PreparedStatement.close() and ResultSet.close() throw a java.sql.SQLException.  So do I add a try/catch block to the finally clause?  Or move the close statements into the try clause?  Or just not bother calling close?
10915
I'm pretty new to coding and I want to get an opinion on my coding. I am learning Python and I made a really simple heads and tails guessing game.  import random import time import easygui import sys while True:     rand = random.choice(["Heads", "Tails"])     firstguess = raw_input("Guess Heads or Tails: ")     if firstguess == rand:         print "Wow you win"     else:         print "That is wrong you suck so bad lol."     time.sleep(2)     answer = easygui.buttonbox("Play again?", choices=["Yes","No"])     if answer == "Yes":         easygui.msgbox("Ok")     else:         break  easygui.msgbox("Ok, see you later!") sys.exit(0)
62033
I have a question about comparing a string with the empty string in Java. Is there a difference, if I compare a string with the empty string with == or equals? For example:  String s1 = "hi";  if (s1 == "")   or   if (s1.equals(""))    I know that one should compare strings (and objects in general) with equals, and not ==, but I am wondering whether it matters for the empty string.
24218
Is this functionality going to be put into a later Java version?  Can someone explain why I can't do this, as in, the technical way Java's switch statement works?
40125
Take the following sentence:     And even if the program inputted one token and then invoked newLine(), wouldn't it input a blank?   I've been told that this sentence has a clear pronoun reference. Why? Couldn't it refer to either program or token?