I tried to simulate a 400 meters race using multithreading concept.In this application totally 5 groups are created and they are named by country names,each group should have 2 players.First player is allowed to run for the first 200 meters followed by the next player in the group and the winner group has to be announced.Since i am a beginner in multithreading concept i tried to implement the first 200 meters process without concerning the next 200 meters process.But running the code doesnt print anything on the console.please help me to get through this...  RelayDemo.java  public class RelayDemo implements Runnable {     public void race()     {         for(int i=0;i&lt;200;i++)         {             if(Thread.currentThread().getName()=="rakesh"||Thread.currentThread().getName()=="nathan"||Thread.currentThread().getName()=="max"||Thread.currentThread().getName()=="villiers"||Thread.currentThread().getName()=="decapro")         {             System.out.println("The distance covered by"+Thread.currentThread().getName()+"is "+i);         }      } } public void run() {     this.race(); } }   ExcecuteRelay.java  public class ExcecuteRelay {  public static void main(String[] args)  {     RelayDemo r=new RelayDemo();     ThreadGroup t1=new ThreadGroup("india");     ThreadGroup t2=new ThreadGroup("australia");     ThreadGroup t3=new ThreadGroup("usa");     ThreadGroup t4=new ThreadGroup("africa");     ThreadGroup t5=new ThreadGroup("france");     Thread r1=new Thread(t1,r,"rakesh");     Thread r2=new Thread(t1,r,"kishore");     Thread r3=new Thread(t2,r,"nathan");     Thread r4=new Thread(t2,r,"johnson");     Thread r5=new Thread(t3,r,"max");     Thread r6=new Thread(t3,r,"tim");     Thread r7=new Thread(t4,r,"villiers");     Thread r8=new Thread(t4,r,"duminy");     Thread r9=new Thread(t5,r,"decapro");     Thread r10=new Thread(t5,r,"lues");     r1.start();     r2.start();     r3.start();     r4.start();     r5.start();     r6.start();     r7.start();     r8.start();     r9.start();     r10.start();         // TODO Auto-generated method stub  }  }
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?
111277
I have some doubts regarding net run rate in the ongoing ICC world twenty 20 2014 event.It takes a while to read so please don't hesitate and give me a solution regarding this.    My doubt is that in match 12 of world twenty 20 2014(In Group Stage Last Match on march 21 2014) () Wesley Barresi of Netherlands hit a six when the team score was 187 while chasing Ireland score of 189, That take Netherlands score to 193.  If that is the case in match 17 between India and West Indies in match of super10 group (in ICC world twenty 20 2014 on march 23 2014) () while Suresh Raina (India) hit a four when the team score was 129 while chasing West Indies score of 129,That takes India Only To 130. why Only One run is added to the score in this match(match 17 on march 23 2014) while 6 runs are added to the score in match 12 on march 21 2014.  I don't understand the strategy behind this.Because if India's Score is taken as 133 then India's net run rate as of now(24 march 2014) will be 0.442(Runs Scored For 264 in 38.1 overs ) But Now it is only 0.383(Runs Scored For 261 in 38.1 overs ).As the net run rate plays an important role in the tournaments like this i am not very happy with this.  As being an Indian Fan now a days I look a lot in to net run rate as it has eliminated India in many tournaments including last ICC world twenty 20 2012.  Is There Any One who can clarify my doubts regarding the net run rate as i want to be sure of what was happening?
106050
Hi I'm pretty new to Stack Overflow so I hope that I'm doing this correctly and that someone out there has the answer I need.  I'm currently coding a program in Java with Eclipse IDE an my question is this:  I need a snippet of code that does the following  It's supposed to get a .TXT file containing text and from that .TXT file  count the number of rows and print it,  count the number of words and print it,  count the number of characters and print it. And finally make a list of the top 10 words used and print that.  Allt the printing is done to system outprintln  I'm pretty new to Java and am having some difficulties.  Anyone out there who can provide me with these lines of code or that knows where i can find them? I want to study the code provided that's how I learn best=)  Thanks to all   Didnt find the edit button sorry...  I Added this to my question:  Hehe it´s an assignment but not a homework assignment ok i see well i could provide what i've done so far, i think im pretty close but it´s not working for me. Is there anything i have missed?  // Class    Tip   import java.io.*; import java.util.*;  class Tip {     public static void main(String [] args) throws Exception     {          String root = System.getProperty("user.dir");            InputStream is = new FileInputStream( root + "\\tip.txt" );         Scanner scan = new Scanner( is );          String tempString = "";         int lines = 0;         int words = 0;         Vector&lt;Integer&gt; wordLength = new Vector&lt;Integer&gt;();         int avarageWordLength = 0;          while(scan.hasNextLine() == true)         {                 tempString = scan.nextLine();                 lines++;         }          is.close();          is = new FileInputStream( root );         scan = new Scanner( is );          while(scan.hasNext() == true)         {                 tempString = scan.next();                 wordLength.add(tempString.length());                 words++;         }          for(Integer i : wordLength)         {                 avarageWordLength += i;         }         avarageWordLength /= wordLength.size();           System.out.println("Lines : " + lines);         System.out.println("Words : " + words);         System.out.println("Words Avarage Length : " + avarageWordLength);          is.close();          } }
9051
Check out the below program.   try {     for (String data : Files.readAllLines(Paths.get("D:/sample.txt"))){         String[] de = data.split(";");         System.out.println("Length = " + de.length);     } } catch (IOException e) {     e.printStackTrace(); }   Sample.txt:   1;2;3;4 A;B;; a;b;c;   Output:   Length = 4 Length = 2 Length = 3   Why second and third output is giving 2 and 3 instead of 4. In sample.txt file, condition  for 2nd and 3rd line is should give newline(\n or enter) immediately after giving delimiter for the third field. Can anyone help me how to get length as 4 for 2nd and 3rd line without changing the condition of the sample.txt file and how to print the values of de[2] (throws  ArrayIndexOutOfBoundsException)?
34987
Trying to study for my mid-term, but I'm having slight difficulties understanding what I'm supposed to do in this one problem:  A batter starts running towards first base at a constant speed of 6 m/s. The distance between each adjacent plate is 27.5 m. After running for 20 m, how fast is he approaching second base? At the same moment, how fast is he running away from third base? (see image below)    This is what I have so far:   Let $d$ be the distance the batter has run thus far The distance between the batter and first base is 7.5 m The distance between the batter and second base is $\sqrt {27.5^2 + (27.5-d)^2}\ $, or approx. 28.5044 m when $d = 20$ The distance between the batter and third base is $\sqrt {27.5^2 + d^2}\ $, or approx. 34.0037 m when $d = 20$   No need to hand feed me the answer, I'd just like a bit of insight on how to solve the problem.
84853
Comment on Duplicate Reference: Why would this be marked duplicate when it was asked years prior to the question referenced as a duplicate?  I also believe the question, detail, and response is much better than the referenced question.  I've been a C++ programmer for quite a while but I'm new to Java and new to Eclipse.  I want to use the  to visualize some data I'm working with.  This code is organized like this:  ./com ./com/touchgraph ./com/touchgraph/graphlayout ./com/touchgraph/graphlayout/Edge.java ./com/touchgraph/graphlayout/GLPanel.java ./com/touchgraph/graphlayout/graphelements ./com/touchgraph/graphlayout/graphelements/GESUtils.java ./com/touchgraph/graphlayout/graphelements/GraphEltSet.java ./com/touchgraph/graphlayout/graphelements/ImmutableGraphEltSet.java ./com/touchgraph/graphlayout/graphelements/Locality.java ./com/touchgraph/graphlayout/graphelements/TGForEachEdge.java ./com/touchgraph/graphlayout/graphelements/TGForEachNode.java ./com/touchgraph/graphlayout/graphelements/TGForEachNodePair.java ./com/touchgraph/graphlayout/graphelements/TGNodeQueue.java ./com/touchgraph/graphlayout/graphelements/VisibleLocality.java ./com/touchgraph/graphlayout/GraphLayoutApplet.java ./com/touchgraph/graphlayout/GraphListener.java ./com/touchgraph/graphlayout/interaction ./com/touchgraph/graphlayout/interaction/DragAddUI.java ./com/touchgraph/graphlayout/interaction/DragMultiselectUI.java ./com/touchgraph/graphlayout/interaction/DragNodeUI.java ./com/touchgraph/graphlayout/interaction/GLEditUI.java ./com/touchgraph/graphlayout/interaction/GLNavigateUI.java ./com/touchgraph/graphlayout/interaction/HVRotateDragUI.java ./com/touchgraph/graphlayout/interaction/HVScroll.java ./com/touchgraph/graphlayout/interaction/HyperScroll.java ./com/touchgraph/graphlayout/interaction/LocalityScroll.java ./com/touchgraph/graphlayout/interaction/RotateScroll.java ./com/touchgraph/graphlayout/interaction/TGAbstractClickUI.java ./com/touchgraph/graphlayout/interaction/TGAbstractDragUI.java ./com/touchgraph/graphlayout/interaction/TGAbstractMouseMotionUI.java ./com/touchgraph/graphlayout/interaction/TGAbstractMousePausedUI.java ./com/touchgraph/graphlayout/interaction/TGSelfDeactivatingUI.java ./com/touchgraph/graphlayout/interaction/TGUIManager.java ./com/touchgraph/graphlayout/interaction/TGUserInterface.java ./com/touchgraph/graphlayout/interaction/ZoomScroll.java ./com/touchgraph/graphlayout/LocalityUtils.java ./com/touchgraph/graphlayout/Node.java ./com/touchgraph/graphlayout/TGAbstractLens.java ./com/touchgraph/graphlayout/TGException.java ./com/touchgraph/graphlayout/TGLayout.java ./com/touchgraph/graphlayout/TGLensSet.java ./com/touchgraph/graphlayout/TGPaintListener.java ./com/touchgraph/graphlayout/TGPanel.java ./com/touchgraph/graphlayout/TGPoint2D.java ./com/touchgraph/graphlayout/TGScrollPane.java ./TG-APACHE-LICENSE.txt ./TGGL ReleaseNotes.txt ./TGGraphLayout.html ./TGGraphLayout.jar   How do I add this project in Eclipse and get it compiling and running quickly?
1612
From what time I've spent with threads in Java, I've found these two ways to write threads:  With implements Runnable:  public class MyRunnable implements Runnable {     public void run() {         //Code     } } //Started with a "new Thread(new MyRunnable()).start()" call   Or, with extends Thread:  public class MyThread extends Thread {     public MyThread() {         super("MyThread");     }     public void run() {         //Code     } } //Started with a "new MyThread().start()" call   Is there any significant difference in these two blocks of code ?
49572
What is the maximum number of threads you can create in a C# application?  And what happens when you reach this limit?  Is an exception of some kind thrown?
41754
I'm a programmer but I don't know much about stats, so please excuse me if this question sounds naive.  I have two computers that are in different locations.  I have made N measurements for the network distance between them.  So it's essentially a series of N numbers like 200ms, 173ms, 212ms....  Now, I need to write a simulator that simulates these two computers.  What I need is a generator that can generate new network distances between them.  So for instance, if the generator generates something like 183ms, then it'd be reasonable.  But if it generates, say, 1 billion ms, then that wouldn't make sense since it deviates so much from the original data set.  So how would I generate new numbers that are similar to the numbers in the original series?  P.S. I'm not sure what tags I should use for this question because I don't know much about stats... feel free to add tags that you think are more appropriate.
2338
I have a server application that uses "a lot" of threads. Without wanting to get into an argument about how many threads it really should be using, it would be nice to be able to see some descriptive text in the debugger "threads" window describing what each one is, without having to click through to it and determine from the context what it is.  They all have the same start address so generally the threads window says something like "thread_base::start" or something similar. I'd like to know if there is an API call or something that allows me to customise that text.
68092
So, I've got a question for class that asks me to prove the existence of arbitrarily long runs of consecutive integers where $\mu(n)$ is zero.   I've started the proof, but I need a bit of help midway through.  Assume there exists a run of length n, which we currently assume is the longest possible chain.  If we induct on n, we can assume there is a run of the form $m_1p_1^2, m_2p_2^2, ..., m_np_n^2$ (where each of the $p_i$ are prime).  If I add $M =  lcm(m_1p_1^2, m_2p_2^2, ..., m_np_n^2)$ to each number, I get another run of length n.  So here's where the issue starts. When I talked to my advisor about it, he referenced a theorem where there exists a prime $p$ congruent to $1\ mod\ M$.  I am unfamiliar with this theorem, so I'm not sure how to use this information. Any chance I can get some help? Or else is there a simpler way to go about this problem?
10864
I was wondering how to implement time travel into a game. Nothing super complex, just time-reversal like what's in Braid, where the user can rewind/fast forward time by 30 seconds or whatever.  I searched around the web a lot, but my results usually referred to using time as in like "it's 3:00" or a timer and such.  The only thing I could think of was using 2 arrays, one for the player's x position and the other for the player's y position, and then iterating through those arrays and placing the character at that position as they rewind/fast forward time. Could that work? If it would work, how large would the array have to be and how often should I store the player's x and y? If it doesn't work, what else could I try?  Thanks in advance!
5088
In the  it says:     A thread can be flagged as a "daemon thread". The significance of this   flag is that the entire Python program exits when only daemon threads   are left. The initial value is inherited from the creating thread.   Does anyone have a clearer explanation of what that means or a practical example showing where you would set threads as daemonic?  Clarify it for me: so the only situation you wouldn't set threads as daemonic, is when you want them to continue running after the main thread exits?
439
Consider:  namespace WindowsApplication1 {     public partial class Form1 : Form     {         public Form1()         {             InitializeComponent();         }          private void button1_Click(object sender, EventArgs e)         {             //int[] val = { 0, 0};             int val;             if (textBox1.Text == "")             {                 MessageBox.Show("Input any no");             }             else             {                 val = Convert.ToInt32(textBox1.Text);                 Thread ot1 = new Thread(new ParameterizedThreadStart(SumData));                 ot1.Start(val);             }         }          private static void ReadData(object state)         {             System.Windows.Forms.Application.Run();         }          void setTextboxText(int result)         {             if (this.InvokeRequired)             {                 this.Invoke(new IntDelegate(SetTextboxTextSafe), new object[] { result });             }             else             {                 SetTextboxTextSafe(result);             }         }          void SetTextboxTextSafe(int result)         {             label1.Text = result.ToString();         }          private static void SumData(object state)         {             int result;             //int[] icount = (int[])state;             int icount = (int)state;              for (int i = icount; i &gt; 0; i--)             {                 result += i;                 System.Threading.Thread.Sleep(1000);             }             setTextboxText(result);         }          delegate void IntDelegate(int result);          private void button2_Click(object sender, EventArgs e)         {             Application.Exit();         }     } }   Why is this error occurring?     An object reference is required for the nonstatic field, method, or property 'WindowsApplication1.Form1.setTextboxText(int)
36629
I was wondering if in Java I would get any odd behaviour if I synchronise twice on the same object?  The scenario is as follows  pulbic class SillyClassName {      object moo;     ...     public void method1(){         synchronized(moo)         {             ....             method2();             ....         }     }      public void method2(){         synchronized(moo)         {             doStuff();         }     } }   Both methods use the object and are synchronised on it. Will the second method when called by the first method stop because it's locked?  I don't think so because it's the same thread but I'm unsure of any other odd results that might occur.
46496
Hi there I am planning a ”Scavenger hunt”-like activity (I have no other words for this event), and I am having trouble creating the schedule.   The idea of this hunt/run/game/competition is that 10 teams will battle each other at X different mini games. The games on are team vs. team based, meaning that there will always be two teams on each post and one winner and one loser.  I require that every team fights every other team. Meaning that team 1 will have to meet team 2, 3, 4, 5, 6, 7, 8, 9, and 10, and team 2 will have to meet team 1, 3, 4, 5, 6, 7, 8, 9, 10 (and so forth). The amount of mini games must be so, that every team only meets the other teams ONCE each, but still they have to meet every team.  How many posts do I need to create, and how could I schedule the overall activity? (A table of rounds and teams would be much appreciated).
16473
Consider the class below that represents a Broker:  public class Broker {     public string Name = string.Empty;     public int Weight = 0;      public Broker(string n, int w)     {         this.Name = n;         this.Weight = w;     } }   I'd like to randomly select a Broker from an array, taking into account their weights.  What do you think of the code below?  class Program     {         private static Random _rnd = new Random();          public static Broker GetBroker(List&lt;Broker&gt; brokers, int totalWeight)         {             // totalWeight is the sum of all brokers' weight              int randomNumber = _rnd.Next(0, totalWeight);              Broker selectedBroker = null;             foreach (Broker broker in brokers)             {                 if (randomNumber &lt;= broker.Weight)                 {                     selectedBroker = broker;                     break;                 }                  randomNumber = randomNumber - broker.Weight;             }              return selectedBroker;         }           static void Main(string[] args)         {             List&lt;Broker&gt; brokers = new List&lt;Broker&gt;();             brokers.Add(new Broker("A", 10));             brokers.Add(new Broker("B", 20));             brokers.Add(new Broker("C", 20));             brokers.Add(new Broker("D", 10));              // total the weigth             int totalWeight = 0;             foreach (Broker broker in brokers)             {                 totalWeight += broker.Weight;             }              while (true)             {                 Dictionary&lt;string, int&gt; result = new Dictionary&lt;string, int&gt;();                  Broker selectedBroker = null;                  for (int i = 0; i &lt; 1000; i++)                 {                     selectedBroker = GetBroker(brokers, totalWeight);                     if (selectedBroker != null)                     {                         if (result.ContainsKey(selectedBroker.Name))                         {                             result[selectedBroker.Name] = result[selectedBroker.Name] + 1;                         }                         else                         {                             result.Add(selectedBroker.Name, 1);                         }                     }                 }                   Console.WriteLine("A\t\t" + result["A"]);                 Console.WriteLine("B\t\t" + result["B"]);                 Console.WriteLine("C\t\t" + result["C"]);                 Console.WriteLine("D\t\t" + result["D"]);                  result.Clear();                 Console.WriteLine();                 Console.ReadLine();             }         }     }   I'm not so confident. When I run this, Broker A always gets more hits than Broker D, and they have the same weight.  Is there a more accurate algorithm?  Thanks!