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 difference between protected and private?
What are synchronized methods and synchronized statements in java programming?
What is api in java?
What is the purpose of format function?
Difference between ‘is-a’ and ‘has-a’ relationship in java?
What are predefined functions?
Can inner class be public in java?
What is difference between stringbuffer and string?
How do you generate random numbers in java?
What is runtime polymorphism or dynamic method dispatch?
Give differences between Quicksort &Mergesort. When should these sorts be used andwhat is their running time in java?
What are passing parameters?
Can we make a constructor final?
Is main is a keyword?
What is the best definition for data?