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
Program to Find the second largest element in an array.
What are the differences between checked exception and unchecked exception?
Can final class have constructor?
What should I import for arraylist in java?
What are reference variables in java?
What is multithreading in java?
Why should I use abstract class?
How do you do descending order in java?
What is the difference between overriding and overloading in OOPS.
Can we create a constructor in abstract class?
Why array is used in java?
What is classname class in java?
Explain about varargs in java?
What is instance example?
What kind of variables a class can consist of?