This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Hi, i have couple questions for this program.(i got this code from JAVA 2) // Char class Char { public static void main (String args[]) { char ch;
ch = 'X'; System.out.println ("ch contains " + ch); ch++; System.out.println ("ch is now " + ch); ch = 90; System.out.println ("ch is now " + ch); } } 1. on the ' public static void main (String args[])', but i looked another book 'Thinking in JAVA by Bruce Eckel' and he wrote '(String[] args)'. what's the different? 2. on this output 'ch is now z' not 90 because from ASCII. can you tell me where i can find this document? thank you for your help. yuan
karl koch
Ranch Hand
Joined: May 25, 2001
Posts: 388
posted
0
hi for your second question: ascii coed table check out the ASCII value in the row where DECIMAL value is 90. for the first: there is no difference. that easy.
i dont know the exact reason for this. i prefer the String[] way. k
Layne Lund
Ranch Hand
Joined: Dec 06, 2001
Posts: 3061
posted
0
Originally posted by karl koch: ascii coed table
An ascii co-ed table eh? :roll: Are the lower-case ones female?
Maybe the mixed case ones are definitely teenagers. doco
doco
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
posted
0
String myStringArray[]; // is for us old C programmers ( well not quite: char* myStringArray[10] would be it ) String[] myStringArray; // is for cool kids [ March 18, 2003: Message edited by: Barry Gaunt ]
The different syntax styles also allow for unnecessarily compounded declarations of different data types. int a, b[]; a would be an int while b would be an int array.
I am interested in this topic. But I am a little confused. Does this mean that we use String a[] to creat an array a[] with type String and, on the other hand, we use String[] a to creat a, which is an array of String (String[])?
Jonas Isberg
Ranch Hand
Joined: Mar 18, 2003
Posts: 118
posted
0
Originally posted by Shen Lin: I am interested in this topic. But I am a little confused. Does this mean that we use String a[] to creat an array a[] with type String and, on the other hand, we use String[] a to creat a, which is an array of String (String[])?
String a[] is an array of Strings, the array is named a. String[] a is an array of Strings, this array is also named a. (The type of a is in both cases String[].)
karl koch
Ranch Hand
Joined: May 25, 2001
Posts: 388
posted
0
hi now that i reread my post...douuuugh but no worries: i wont correct my typo so you can continue to make fun of it :-)
k
Donald R. Cossitt
buckaroo
Ranch Hand
Joined: Jan 31, 2003
Posts: 401
posted
0
String a[] is an array of Strings, the array is named a. String[] a is an array of Strings, this array is also named a. (The type of a is in both cases String[].)
What is the advantage of using one over the other? Or when would one use String[] a and not String a[]? doco
Corey McGlone
Ranch Hand
Joined: Dec 20, 2001
Posts: 3271
posted
0
Originally posted by doco mastadon:
What is the advantage of using one over the other? Or when would one use String[] a and not String a[]? doco
They are equivalent expressions. There is no advantage of one over the other.
Unless you consider those unnecessarily compounded declarations an advantage. I'd tend to consider the ability to do funny things like that a curse.
Candy Bortniker
Ranch Hand
Joined: Mar 17, 2003
Posts: 123
posted
0
Ok, I was reading through here to see if I could offer advice or more likely learn something, then I got confused. I thought that arrays could be only int or float, etc. I just learned about vectors, similar to arrays but they hold objects such as strings. Am I misunderstanding something?
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
posted
0
Candy, since your question is a bit different from this thread's topic, I've begun a new thread for you where we can discuss your question. [ March 19, 2003: Message edited by: Dirk Schreckmann ]