how to print a numbers from 1 to 100 with out using control
structures?
Answer Posted / gayitri91
import java.io.*;
class Sample
{
public void printTo100(){
int[] array = new int[101];
try{
printToArrayLimit(array, 1);
}catch(ArrayIndexOutOfBoundsException e){
}
}
public void printToArrayLimit(int array[] , int index){
array[index] = array[index-1]+1;
System.out.println(array[index]);
printToArrayLimit(array, index+1);
}
public static void main(String ar[])
{
Sample s=new Sample();
s.printTo100();
}
}
| Is This Answer Correct ? | 13 Yes | 0 No |
Post New Answer View All Answers
How to optimize the javac output?
Can singleton class be serialized?
What is jpa specification?
What will happen when using pass by reference in java?
What is numel matlab?
What is the common usage of serialization?
What is prefix of a string?
What is a JAR file?
Explain polymorphism citing an example.
When should I use stringbuffer?
What is the difference amongst jvm spec, jvm implementation, jvm runtime ?
What is the exact difference in between unicast and multicast object? Where we will use?
How does java pattern compile work?
Which command from the jdk compiles a java program?
Can we assign integer value to char in java?