how to print a numbers from 1 to 100 with out using control
structures?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
Explain runtime exceptions?
what is polymorphism with example?types of polymorphism?
What causes memory leaks in java?
How do we make a class serialize?
What does java se mean?
Can there be an abstract class with no abstract methods in it?
Can we change the value of static variable?
What is the difference between overriding and overloading in OOPS.
0 Answers Axtria, ITC Indian Tobacco Company,
What does a method signature consist of?
Is there any limitation of using inheritance?
What is hash in java?
What is executor memory?