while (x == 1)    {        String[] riddles = new String[5] ;             riddles[0] = ("Hellowrite1") ;           riddles[1] = ("write2") ;           riddles[2] = ("write3") ;           riddles[3] = ("write4") ;           riddles[4] = ("write5") ;          String[] answers = new String [5] ;           answers[0] = ("1") ;           answers[1] = ("2") ;           answers[2] = ("3") ;           answers[3] = ("4") ;           answers[4] = ("5") ;  int riddlenumber;    riddlenumber = rand.nextInt (5);    System.out.println (riddles [riddlenumber]);    String useranswer;    useranswer = scan.next();    if   how would I continue the if statement? I want the if statement to compare the user answer with the corresponding string from the answers String. Basically I want it to say, if the string useranswer = answer String #(riddlenumber, the number chosen with the random function), then system.out.println("yay"); else -----
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?
101984
I am iterating over a list and I want to print out the index of the item if it meets a certain condition. How would I do this?  Example:    testlist = [1,2,3,5,3,1,2,1,6] for item in testlist:     if item == 1:         print position
81943
How does one parse an integer to string(char* || char[]) in C? Is there an equivalent to the Integer.parseInt(String) method from Java in C?
58615
Have you ever tried this before?  static void Main(string[] args) {     int x = 10;     x = x++;     Console.WriteLine(x); }   Output: 10.  but for   static void Main(string[] args) {     int x = 10;     x++;     Console.WriteLine(x); }   Output: 11.  Could anyone explain why this?
14717
The problem is: Find $C_n$, the number of all ternary strings (length $n≥0$) that don't have consecutive 1's and 2's, using combinatorics.   Any tips or advices?
10523
I know how to do it normally, but I could swear that you could fill out out like a[0] = {0,0,0,0}; How do you do it that way? I did try Google, but I didn't get anything helpful.
6251
Choose a random number between $0$ and $1$ and record its value. Do this again and add the second number to the first number. Keep doing this until the sum of the numbers exceeds $1$. What's the expected value of the number of random numbers needed to accomplish this?
5691
Is there a better way of getting this result? This function fails if num has more digits than digits, and I feel like it should be in the library somewhere (like Integer.toString(x,"%3d") or something)  static String intToString(int num, int digits) {     StringBuffer s = new StringBuffer(digits);     int zeroes = digits - (int) (Math.log(num) / Math.log(10)) - 1;      for (int i = 0; i &lt; zeroes; i++) {         s.append(0);     }     return s.append(num).toString(); }
24750
I've just encountered a weird problem, I'm trying to printf an integer variable, but I forgot to specify the variable name, i.e.  printf("%d");   instead of  printf("%d", integerName);   Surprisingly the program compiles, there is output and it is not random. In fact, it happens to be the very integer I wanted to print in the first place, which happens to be m-1.  The errorneous printf statement will consistently output m-1 for as long as the program keeps running... In other words, it's behaving exactly as if the statement reads  printf("%d", m-1);   Anybody knows the reason behind this behaviour? I'm using g++ without any command line options.  #include &lt;iostream&gt; #define maxN 100 #define ON 1 #define OFF 0  using namespace std;  void clearArray(int* array, int n); int fillArray(int* array, int m, int n);  int main() {     int n = -1, i, m;     int array[maxN];     int found;      scanf("%d", &amp;n);      while(n!=0)     {         found=0;         m = 1;         while(found!=1)         {             if(m != 2 &amp;&amp; m != 3 &amp;&amp; m != 4 &amp;&amp; m != 6 &amp;&amp; m != 12)             {                 clearArray(array, n);                 if(fillArray(array, m, n) == 0)                 {                     found = 1;                 }             }             m++;         }          printf("%d\n");          scanf("%d", &amp;n);     }      return 0; }  void clearArray(int* array, int n) {     for(int i = 1; i &lt;= n; i++)         array[i] = ON; }  int fillArray(int* array, int m, int n) {     int i = 1, j, offCounter = 0, incrementCounter;      while(offCounter != n)     {         if(*(array+i)==ON)          {             *(array+i) = OFF;             offCounter++;                }         else          {             j = 0;             while((*array+i+j)==OFF)             {                 j++;             }             *(array+i+j) = OFF;             offCounter++;                    }         if(*(array+13) == OFF &amp;&amp; offCounter != n) return 1;         if(offCounter ==n) break;          incrementCounter = 0;                while(incrementCounter != m)         {             i++;             if(i &gt; n) i = 1;             if(*(array+i) == ON) incrementCounter++;          }            }      return 0; }
36777
What is the difference between == and === in JavaScript?  I have also seen != and !== operators.  Are there more such operators?
87341
An array is defined to be maxmin equal if it contains at least two different elements and the number of times the maximum value occur is the same as the number of times the minimum value occur. So {11, 4, 9, 11, 8, 5 , 4, 10} is maxmin equal, because the max value 11 and min value 4 both appear two times in the array.   if the input array is {} , isMaxMinEqual should return false (array must have at least two different elements) status = false; if the input array is {2}, isMaxMinEqual should return false (array must have at least two different elements). if the input array is {1,1,1,1,1,1}, isMaxMinEqual should return false (array must have at least two different elements).  if the input array is {2,4,6,8,11}, isMaxMinEqual should return true (Both max value(11) and min value 2 appear exactly one time). if the input array is {-2,-4,-6,-8,-11}, isMaxMinEqual should return true(Both max value(-2) and min value -11 appear exaclty one time).   I wrote the class MaxMin which satisfied the above condition.  public class MaxMin {  public static void main(String args[]) {     System.out.println("The result is: " + isMaxMinEqual(new int[]{2, 2})); }  public static boolean isMaxMinEqual(int[] a) {     boolean status = false;     int count = 0;     if (a.length &lt; 2) {         status = false;         return status;     }     for (int i = 1; i &lt; a.length; i++) {         if (a[i - 1] != a[i]) {             count++;         }     }      int max = a[0];     int min = a[0];     for (int i = 0; i &lt; a.length; i++) {         if (a[i] &gt; max) {             max = a[i];         } else if (a[i] &lt; min) {             min = a[i];         }     }      int maxCount = 0;     for (int j = 0; j &lt; a.length; j++) {         if (a[j] == max) {             maxCount++;         }     }      int minCount = 0;     for (int j = 0; j &lt; a.length; j++) {         if (a[j] == min) {             minCount++;         }     }     System.out.println(count);     System.out.println("max is: " + max);     System.out.println("min is: " + min);     System.out.println("Max Count is: " + maxCount);     System.out.println("Min Count is: " + minCount);      if (maxCount == minCount &amp;&amp; count &gt;= 1) {         status = true;     }      return status; } }
33592
I have a group of strings in Javascript and I need to write a function that detects if another specific string belongs to this group or not.  What is the fastest way to achieve this? Is it alright to put the group of values into an array, and then write a function that searches through the array?  I think if I keep the values sorted and do a binary search, it should work fast enough. Or is there some other smart way of doing this, which can work faster?
120783
This is what I have so far:    myArray.map!{ rand(max) }   Obviously, however, sometimes the numbers in the list are not unique. How can I make sure my list only contains unique numbers without having to create a bigger list from which I then just pick the n unique numbers?  Edit: I'd really like to see this done w/o loop - if at all possible.
3282
Answer: Ternary strings have symbols 0, 1, and 2. If there is exactly one 1, then there are 3 positions the one can be in and 2*2*2 ways to fill the other 3 blanks with a 0 or a 2. So the answer is 3*2*2*2 = 24.  I don't understand why there can only be 3 positions the one can be in?
83024
I have two arrays:  arrayA=(1 2 3) arrayB=(a b c)   and I want to print out one of them using a command line argument, i.e., without any if else.  I tried a few variations on the syntax with no success. I am wanting to do something like this:  ARG="$1"  echo ${array${ARG}[@]}   but I get a "bad substitution" error. How can I achieve this?
31694
Given a function which produces a random integer in the range 1 to 5, write a function which produces a random integer in the range 1 to 7.   What is a simple solution? What is an effective solution to reduce memory usage or run on a slower CPU?
31203
Is there a package that provides a command for testing whether a string is in a list?  I saw several answers that define their own commands to perform this or similar tasks, but I prefer a "self-evolving", and well-documented solution for this kind of tasks.  More precisely, the command should be something like this  \IfStringInList{string}{list}{DoThisIfTrue}{DoThisIfFalse}   For instance  \IfStringInList{Paul}{George,John,Paul,Ringo}{Beat it}{Roll it}   EDIT:  I'm not against defining commands.  I expected thas this natural functionality was present in a ready-to-use package, that can be accessed in a very simple way.