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 many types of java are there?
What is the difference between serializable and externalizable interface?
Can extern variables be initialized?
What is blank final variable?
What are different types of multitasking?
Explain about core java?
Explain the reason behind ending a program with a system.exit(0)?
Which class is the superclass for all the classes?
Write a program to print all permutations of string?
How to declare an arraylist in java?
Why is stringbuffer called mutable?
Why array is used in java?
What is a finally block?
What are computer functions?
What does void * mean?