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
Can size_t be negative?
What is the relationship between clipping and repainting under awt?
What is isa relationship?
Can you have two constructors in java?
What is difference between string and new string?
What is method overloading and method overriding?
What is the final field modifier?
What is fail fast in java?
Why method overriding is used?
What does the @override annotation do?
What is meant by local variable and instance variable?
what is bmg file and how to create that files?what will it contailn?
Does java support Operator Overloading?
Can you use abstract and final both with a method?
Can private class be inherited in java?