473,401 Members | 2,068 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,401 software developers and data experts.

Comparing three variables with another three variables

I am doing a Java ME project which acquires input such as current location and destination from the use and then display the appropriate information such as bus service to take, travel time and image of the bus stop.

So here the problem...

There are three bus services for each location.
Location 1: 95, 100, 14
Location 1: 20, 14, 144 where 20 95 100 and 14 are the bus number.

i have retrieved the bus services from mysql.
they are stored as String types
cbus1,cbus2,cbus3 (services for current location) and
dbus1, dbus2, dbus3 (services for destination).

I need to run through them get the services that are present in both the current location and destination.

I have initialized three variables common1, common2, common3 to 0.

I need to store the value of the common services in these three variables.

After they are stored I will use a very simple but long if else statement to combine them as a variable and send to the midlet.
Expand|Select|Wrap|Line Numbers
  1. if (common1==0&&common2==0 &&common3==0){
  2. String bussvc = "No Services available";
  3. }
  4. else if (common2==0 &&common3==0){
  5. String bussvc = Integer.toString(common1);
  6. }
  7. else if (common1==0 && common3==0){
  8. String bussvc = Integer.toString(common2);
  9. }
  10. else if (common1==0 && common2==0){
  11. String bussvc = Integer.toString(common3);
  12. }
  13. else if (common1==0 && common2==0){
  14. String bussvc = Integer.toString(common3);
  15. }
  16. else if (common3==0){
  17. String bussvc = ""+Integer.toString(common1)+"+","+"+Integer.toString(common1)+""
  18. }
  19.  
  20. .
  21. .
  22. .
  23. .
  24. .
  25.  
  26.  
How do cycle through the bus numbers and get the common ones?
Jul 22 '07 #1
3 2027
JosAH
11,448 Expert 8TB
Have you looked at a Set or even a BitSet?

kind regards,

Jos
Jul 22 '07 #2
How do I use a BITSET to compare the values and store the common ones ?
Jul 23 '07 #3
JosAH
11,448 Expert 8TB
How do I use a BITSET to compare the values and store the common ones ?
Given your example:

Location 1: 95, 100, 14
Location 1: 20, 14, 144

build two bitsets; the first bitset has bits 95, 100 and 14 set; the second one
has bits 20, 14 and 144 set. 'and' the two sets and your're in business.
Read the API docs for the BitSet class and see how it can be done.

kind regards,

Jos
Jul 23 '07 #4

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

Similar topics

41
by: Odd-R. | last post by:
I have to lists, A and B, that may, or may not be equal. If they are not identical, I want the output to be three new lists, X,Y and Z where X has all the elements that are in A, but not in B, and...
6
by: Erwin | last post by:
Suppose I have a string, char *str = "1 2 a f g < )" and I need to check each of the components in the loop using isalpha, isdigit, isspace. How can I do that? I tried to do using this code, but...
11
by: John | last post by:
Hi, I encountered a strange problem while debugging C code for a Windows-based application in LabWindows CVI V5.5, which led me to write the test code below. I tried this code with a different...
89
by: purifier | last post by:
The problem is to write a program in 'C' to find the greatest of 2 given numbers... Easy? huh here's the catch do not use 'if' or any conditional statements if u want it to be a little more...
19
by: Dennis | last post by:
I have a public variable in a class of type color declared as follows: public mycolor as color = color.Empty I want to check to see if the user has specified a color like; if mycolor =...
4
by: Mika M | last post by:
I need to compare two DateTime variables named as t1 and t2 using VB.NET 2003. If t1 is any earlier time as t2, only then program should do something like... If (t1 < t2) Then...
2
by: Pugi! | last post by:
hi, I am using this code for checking wether a value (form input) is an integer and wether it is smaller than a given maximum and greater then a given minimum value: function...
1
by: chiefychf | last post by:
I'm working on a school project and I am having a few issues... The program calls for three arrays a,b,c that have to be sorted, then compared to even or odd and stored in arrays d & e, then merge...
0
by: Gabriel Genellina | last post by:
En Thu, 15 May 2008 06:02:29 -0300, Beema shafreen <beema.shafreen@gmail.comescribió: *three* columns? You menction only two of them. Do you have to syncrhonize both listings? That is,...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.