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


Please Help Members By Posting Answers For Below Questions

How to avoid memory leak in java?

827


When should I use a singleton?

763


what state does a thread enter when it terminates its processing? : Java thread

812


Can we serialize singleton class?

760


Write a program to reverse array in place?

769


What are the benefits of operations?

697


What are facelets templates?

783


What is the static variable?

796


What is difference between string and stringbuffer?

695


What is the current version of java?

755


What does serializing data mean?

716


What do you mean by formatting?

733


When should I use singleton?

696


Is c better than java?

725


When do we need to use internal iteration? When do we need to use external iteration?

822