how to print a numbers from 1 to 100 with out using control
structures?

Answers were Sorted based on User's Feedback



how to print a numbers from 1 to 100 with out using control structures?..

Answer / 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

how to print a numbers from 1 to 100 with out using control structures?..

Answer / vinodh

public class Printnos
{
static int a[]=new int[100];
static int i=1;
public static void main(String args[])
{
try
{
i=add(i);
a[i]=i;
main(args);
}
catch(ArrayIndexOutOfBoundsException e){
System.out.println(i);

}
}
static int add(int i)
{
System.out.println(i);
return ++i;
}
}

Is This Answer Correct ?    2 Yes 0 No

how to print a numbers from 1 to 100 with out using control structures?..

Answer / friend

int i = 1;
System.out.println(i++);
System.out.println(i++);
System.out.println(i++);
System.out.println(i++);
System.out.println(i++);
....................
......................
..................
................

Is This Answer Correct ?    7 Yes 6 No

how to print a numbers from 1 to 100 with out using control structures?..

Answer / sushila

public class Arr
{
static int a[]=new int[100];
static int i=0;
public static void main(String args[])
{
try
{
i=add(i);
a[i]=i;
main(args);
}
catch(ArrayIndexOutOfBoundsException e){

}
}
static int add(int i)
{
System.out.println(++i);
return ++i;
}
}

Is This Answer Correct ?    2 Yes 1 No

Post New Answer

More Core Java Interview Questions

Hi all, I am dng a mini project on FileSplitter application which splits the GBs of logfile into Smaller chunks(mbs) depending on the split size." How to handle GBs file? I am getting OutOfMemoryException, when I input such GB sized file. Thx

0 Answers  


Which is the best approach for creating thread ?

0 Answers  


What are the two major components of JDBC?

5 Answers   CMC, Mind Tree,


What are daemon Threads in java?

0 Answers   Impetus,


What is native method in java?

0 Answers  






Difference between abtsract & final

1 Answers   Nous,


why we cannot declare static variable inside a static method

4 Answers  


Can java program run without jre?

0 Answers  


Is list thread safe in java?

0 Answers  


Does constructor be static?

0 Answers  


String is a immutable objects . it means that string does not change........... But it will be chang......... { String s="kapil"; String s1="raj"; String s=s1; then print(.......) The String has been changed .. how it is possible and why its called immutable objects

7 Answers  


What is return used for in java?

0 Answers  


Categories