This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi, I need help on the following: 1. How to implement a static variable without using the keyword 'static'. 2. Can you give me a scenario which neccesitates the use of only Inner classes to implement without using methods. 3. Is there any way to get a number in words by inputting the same in digits. For eg, if I input 18, it should return 'Eighteen'. Thanks in advance. Regds Sundeep
1. How to implement a static variable without using the keyword 'static'.
Program in a language like Ruby that doesn't use this keyword to denote class variables?
2. Can you give me a scenario which neccesitates the use of only Inner classes to implement without using methods.
To implement what?
3. Is there any way to get a number in words by inputting the same in digits. For eg, if I input 18, it should return 'Eighteen'.
Yes, there is a way; you could write a Java program to do this. Sorry, I don't mean to be rude, but these are clearly homework questions, and simply posting your homework here isn't considered good form. Lots of people here will be glad to help you figure these things out on your own, though. I don't understand the first two questions; they're apparently trick questions which only students in the class might understand, based on something the instructor or textbook said. The third one, I can give you an idea of how to write it: Imagine a HashMap where the keys are Integer objects and the values are String objects. Start by putting in the Integer objects from zero to twenty. Now to print any of these in words, you just have to say System.out.println(myMap.get(new Integer(theNumber)); Of course, this only works for those numbers you put in. Now, for other values, the rules are pretty regular. For the numbers from twenty-one to twenty-nine, you just print the word "twenty" followed by the result of following the first step for the value (theNumber - 20). The same for 31-39, 41-49, etc. So if you add the numbers 30, 40, 50, 60... to your table, then you can do the following to get you up to 99: if there's a value for the number in the table, print it, and you're done. Otherwise, take the number modulo ten, and print the value of looking up (theNumber - remainder) and the remainder itself. Now, you need a rule to handle the values from 100 to 999. Then from 1000 to 9999. Then, you might look back and generalize what you've done...
How to implement a static variable without using the keyword 'static'.
You could declare an interface with a field. This is legal as interface fields are implicitly static (as well as implicitly public and final). Note that it is bad design to use an interface just to declare constants.