473,385 Members | 1,693 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,385 software developers and data experts.

How do i pass a long as the index value of a string array?

I ve got a string array
a[]={"", "One", "Two", "Three", "Four", "Five", "Six", "Seven",
"Eight", "Nine", };

Ive got a method pass().
Inside tat i call another method display()which has a string array as argument.
But as the index of the string array is long, im getiing error.
How to do this?
public void pass(long number) {
long rm, q;
if (number < 10) {
display(a[number]);
}
if (number > 9 && number < 20) {
display(c[number - 10]);
}
if (number > 19) {
rm = number % 10;
if (rm == 0) {
q = number / 10;
display(d[q - 2]);
} else {
q = number / 10;
display(a[rm]);
display(" ");
display(d[q - 2]);
}
}
}

public void display(String s) {
String t;
t = string;
string = s;
string += t;
}
Mar 20 '07 #1
1 1313
r035198x
13,262 8TB
I ve got a string array
a[]={"", "One", "Two", "Three", "Four", "Five", "Six", "Seven",
"Eight", "Nine", };

Ive got a method pass().
Inside tat i call another method display()which has a string array as argument.
But as the index of the string array is long, im getiing error.
How to do this?
public void pass(long number) {
long rm, q;
if (number < 10) {
display(a[number]);
}
if (number > 9 && number < 20) {
display(c[number - 10]);
}
if (number > 19) {
rm = number % 10;
if (rm == 0) {
q = number / 10;
display(d[q - 2]);
} else {
q = number / 10;
display(a[rm]);
display(" ");
display(d[q - 2]);
}
}
}

public void display(String s) {
String t;
t = string;
string = s;
string += t;
}
It's a restriction you have to type cast to int like

Expand|Select|Wrap|Line Numbers
  1.  display(a[(int)number]);
however you may run into problems if your long value is greater than the largest int.

I don't think you will get that problem in your code though.
Mar 20 '07 #2

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

Similar topics

5
by: Seeker | last post by:
Newbie question here... I have a form with some radio buttons. To verify that at least one of the buttons was chosen I use the following code ("f" is my form object) : var btnChosen; for...
1
by: Mark Dicken | last post by:
Hi All I have found the following Microsoft Technet 'Q' Article :- Q210368 -ACC2000: How to Pass an Array as an Argument to a Procedure (I've also copied and pasted the whole contents into...
10
by: nospam | last post by:
Hello! I can pass a "pointer to a double" to a function that accepts double*, like this: int func(double* var) { *var=1.0; ... }
10
by: Sean Dockery | last post by:
I have the following HTML file that I've been using for testing... <html> <head> <script type="text/javascript"> <!-- function handleWindowLoad() { var items = ; for (var i = 0; i < 11; i++)...
14
by: Rich | last post by:
Yes, I need to store some values in an array type collection object that can hold 3 or more parameters per index. I have looked at the collection object, hashtable object and would prefer not to...
2
by: André | last post by:
Hi, I have to pass a lot of variables from vb.net to javascript using client callback. the problem is that there are single variables, but also arrays with differents indexes. I have two...
17
by: Jellicle | last post by:
There are some sturct arrays (or struct vectors), such as: struct S1_t { double keyField ; ..// other fields } S1_t s1;
1
by: Carlos Villaseñor M. | last post by:
Hi everybody! I finally have success implementing my first DLL function, I have exported a C++ function with a DLL using the "Declare" statement in Basic, but now I have a doubt, how can I to...
0
by: liko81 | last post by:
I have an Invoice class that must know, directly or indirectly, how to do anything associated with creating, reading, or otherwise processing an invoice to a customer. It is an uber-DAO object that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.