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 you use abstract and final both with a method?
Give differences between Quicksort & Mergesort. When should these sorts be used and what is their running time?
Differentiate between == and equals().
What is an enumeration?
Explain JMS in detail.
What is the difference between procedural and object-oriented programs?
What are thread groups?
What are dot operator queries?
Explain importance of finally block in java?
Write an algorithm program in java for the following question.. 1) S is a set of integers.X is an integer obtained by sum of two digits in S. Write logic for whether or not the X is from the S. The time of algorithm should not exceed o(n logn).
What is an 8 bit word?
What is sortedmap in java?
What are local variables?
What is the difference between static and non-static variables in java programming?
What does 0 mean in boolean?