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 you use abstract and final both with a method?

569


Give differences between Quicksort & Mergesort. When should these sorts be used and what is their running time?

569


Differentiate between == and equals().

594


What is an enumeration?

566


Explain JMS in detail.

612






What is the difference between procedural and object-oriented programs?

524


What are thread groups?

568


What are dot operator queries?

623


Explain importance of finally block in java?

582


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).

1602


What is an 8 bit word?

590


What is sortedmap in java?

549


What are local variables?

589


What is the difference between static and non-static variables in java programming?

517


What does 0 mean in boolean?

542