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 is string builder in java?
What is the relationship between class and object?
Write a java program to count the number of words present in a string?
Does it matter in what order catch statements for filenotfoundexception and ioexception are written?
Which is bigger float or double java?
Is there a jre for java 11?
Why is an interface be able to extend more than one interface but a class can’t extend more than one class?
What is java algorithm?
Differentiate between a constructor and a method? Can we mark constructors final?
What is implicit object in java?
Can we create our own wrapper class in java?
How to make a read-only class in java?
What is the difference between yield() and sleep()?
What is command line argument
What is multi level inheritance in java?