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
Explain the concept of proper inheritance?
What is a dynamic array in java?
What is formatted output?
Describe the Big-O Notation.
What is deserialization?
Why are constructors used?
What are the types of casting?
What is keyword auto for?
Explain about wait() method?
Is null function in java?
When is the finally clause of a try-catch-finally statement executed?
Explain the Propertie sof class?
Write a java program to generate fibonacci series ?
What are parameters in a method?
What do you understand by classes in java?