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

Is singleton class immutable?

0 Answers  


Can a double value be cast to a byte?

3 Answers  


What is ph and buffers?

0 Answers  


When throw keyword is used?

0 Answers  


When do you get classcastexception?

0 Answers  






Can we instantiate interface in java?

0 Answers  


How to excute - Interface - Inner class- method can any one tell how to execute/ call this main method public interface abc { static int i=0; void dd(); class a1 { a1() { int j; System.out.println("inside"); }; public static void main(String a1[]) { System.out.println("in interfia"); } } }

1 Answers  


Tell us something about set interface.

0 Answers  


We can write any Java Logics in our JSP. Then why we are using servlets(Controller Layer) to interact with the DAO ?

6 Answers   TCS,


How can we achieve IPC in JAVA?

1 Answers   Wipro,


What is 16 bits called?

0 Answers  


Why we need to serialize the object

11 Answers   CTS, Geometric Software,


Categories