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 avoid memory leak in java?
When should I use a singleton?
what state does a thread enter when it terminates its processing? : Java thread
Can we serialize singleton class?
Write a program to reverse array in place?
What are the benefits of operations?
What are facelets templates?
What is the static variable?
What is difference between string and stringbuffer?
What is the current version of java?
What does serializing data mean?
What do you mean by formatting?
When should I use singleton?
Is c better than java?
When do we need to use internal iteration? When do we need to use external iteration?