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

Can size_t be negative?

615


What is the relationship between clipping and repainting under awt?

616


What is isa relationship?

564


Can you have two constructors in java?

503


What is difference between string and new string?

542






What is method overloading and method overriding?

538


What is the final field modifier?

548


What is fail fast in java?

576


Why method overriding is used?

538


What does the @override annotation do?

563


What is meant by local variable and instance variable?

599


what is bmg file and how to create that files?what will it contailn?

1888


Does java support Operator Overloading?

611


Can you use abstract and final both with a method?

573


Can private class be inherited in java?

549