473,387 Members | 3,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

thread help

hi
i have this code and i need some help if possible, i need to enter a new method in the StringCycler class so that each a is always immediately followed by a b.
can anyone help?

Expand|Select|Wrap|Line Numbers
  1. class StringCycler implements Runnable
  2. {
  3.     private String s;
  4.  
  5.     public StringCycler(String s)
  6.     {
  7.         this.s = s;
  8.     }
  9.  
  10.     private void printChar(int i)
  11.     {
  12.         System.out.println(this.s.charAt(i));
  13.     }
  14.  
  15.     private void cycle()
  16.     {
  17.         for (int i = 0; i < this.s.length(); i++)
  18.         {
  19.         this.printChar(i);
  20.         }    
  21.     }
  22.  
  23.     public void run()
  24.     {
  25.         for (;;)
  26.         {    
  27.         this.cycle();
  28.         }
  29.     }
  30. }
  31.  
  32. public class Main
  33. {
  34.     public static void main(String[] args)
  35.     {
  36.     StringCycler c = new StringCycler("abc");
  37.     Thread t1 = new Thread(c);
  38.     Thread t2 = new Thread(c);
  39.     t1.start();
  40.     t2.start();
  41.     }
  42. }
  43.  
Feb 20 '07 #1
1 1161
r035198x
13,262 8TB
hi
i have this code and i need some help if possible, i need to enter a new method in the StringCycler class so that each a is always immediately followed by a b.
can anyone help?

Expand|Select|Wrap|Line Numbers
  1. class StringCycler implements Runnable
  2. {
  3.     private String s;
  4.  
  5.     public StringCycler(String s)
  6.     {
  7.         this.s = s;
  8.     }
  9.  
  10.     private void printChar(int i)
  11.     {
  12.         System.out.println(this.s.charAt(i));
  13.     }
  14.  
  15.     private void cycle()
  16.     {
  17.         for (int i = 0; i < this.s.length(); i++)
  18.         {
  19.         this.printChar(i);
  20.         }    
  21.     }
  22.  
  23.     public void run()
  24.     {
  25.         for (;;)
  26.         {    
  27.         this.cycle();
  28.         }
  29.     }
  30. }
  31.  
  32. public class Main
  33. {
  34.     public static void main(String[] args)
  35.     {
  36.     StringCycler c = new StringCycler("abc");
  37.     Thread t1 = new Thread(c);
  38.     Thread t2 = new Thread(c);
  39.     t1.start();
  40.     t2.start();
  41.     }
  42. }
  43.  
What are you using the threads for here. For the method that you want to write you will need a StringBuilder variable and go thorough the given String appending the string's characters to that variable accordingly.
Feb 20 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: serge calderara | last post by:
Dear all, I have a function that I need to run in a thread due to the fact that it can takes long time to execute according to the amount of data to collect. This function is also populating a...
6
by: Tony Proctor | last post by:
Hi everyone We're experiencing some serious anomalies with the scheduling of ASP threads. I'd be interested to hear if anyone knows what algorithm is used (e.g. simple round-robin, or something...
4
by: Leonardo Hyppolito | last post by:
Hello, I am trying to write a multithread program that simulates producers and consumers. My program can have many producers and many consumers (each in a separate thread). It has a storage...
7
by: Ivan | last post by:
Hi I have following problem: I'm creating two threads who are performing some tasks. When one thread finished I would like to restart her again (e.g. new job). Following example demonstrates...
20
by: Bob Day | last post by:
Using VS 2003, VB, MSDE... There are two threads, A & B, that continously run and are started by Sub Main. They instantiationsl of identical code. Thread A handles call activity on telephone...
7
by: Charles Law | last post by:
My first thought was to call WorkerThread.Suspend but the help cautions against this (for good reason) because the caller has no control over where the thread actually stops, and it might have...
1
by: alundi | last post by:
Greetings: I'd like to post this as a new thread to an article in microsoft.public.dotnet.languages.vb originally made by nevin and replied to by Alan Pretre back in December ("ThreadState ==...
6
by: Sergey Poberezovskiy | last post by:
I have the following code in C# that I have trouble converting to VB(2.0): private delegate void openDialog(); private void openWindowsDialog(openDialog open) { Thread thread = new Thread(new...
8
by: Brad Walton | last post by:
Hello. First post, but been doing a bit of reading here. I am working on a project in Java, but decided to switch over to C# after seeing some of the additional features I can get from C#. One of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.