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
What are the types of inner classes (non-static nested class) used in java?
How can we make a class singleton?
What is java volatile?
What is style and indentation?
What is implicit object in java?
What does yield method of the thread class do?
What exceptions occur during serialization?
What is final modifier?
In which order the iterator iterates over collection?
What are the two types of exceptions in java? Which are the differences between them?
Can we declare a static variable inside a method?
What is an array in java?
What are different exception types exceptions available in java ?
What is public static?
Which variables are stored in heap?