# I'm confused...

• April 14th, 2011, 12:07 PM
acolar
I'm confused...
I was writing a code on how to say a number but my code was horrible so I asked for help. A lot helped but this code caught my attention:

Code :

```import javax.swing.*; public class word {   private static final String[] simple= { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "evelen", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eightteen", "nineteen" };   private static final String[] tens= { null, null, "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety" };   public static String say(int number) { return say(number, true); //default true   }   private static String say(int number, boolean sayZero) { //simulate 123 if (number < 0) return "negative "+say(-number, sayZero); //is 123 < 0? False   if (number == 0) return sayZero?simple[number]:""; //is 123 < 0 ? False   if (number < 20) return simple[number]; //is 123 < 0? false   if (number < 100) return tens[number/10]+say(number%10, false); //is 100 < 100? false   if (number < 1000) return say(number/100, false)+" hundred "+say(number%100); //is 100 < 1000? true--execute say(1) hundred   if (number < 1000000) return say(number/1000, false)+" thousand"+say(number%1000, false);   if (number < 1000000000) return say(number/1000000, false)+" million "+say(number%1000000, false);   return say(number/1000000000, false)+"billion "+say(number%1000000000, false); }   public static void main(String[] args) {   String say = JOptionPane.showInputDialog("Enter a number"); int speak = Integer.parseInt(say); JOptionPane.showMessageDialog(null,say(speak));   }   }```

This code is 100% effective but confusing. So here are my questions:
How does the say() method work?
Why is it that it works even if its not on a loop?
What is the role of boolean here?
• April 14th, 2011, 12:14 PM
KevinWorkman
Re: I'm confused...
Have you stepped through this with a debugger? That's going to help you understand much more effectively than somebody else explaining it will.

What do you mean "how does it work"?