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 many types of java are there?

566


What is the difference between serializable and externalizable interface?

570


Can extern variables be initialized?

516


What is blank final variable?

568


What are different types of multitasking?

550






Explain about core java?

631


Explain the reason behind ending a program with a system.exit(0)?

602


Which class is the superclass for all the classes?

535


Write a program to print all permutations of string?

682


How to declare an arraylist in java?

482


Why is stringbuffer called mutable?

567


Why array is used in java?

521


What is a finally block?

568


What are computer functions?

484


What does void * mean?

537