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

how a programmer confirms that the data submitted has been succesfully inserted into the database(either oracle or my sql).. How a programmer confirm if there is any problem with the program he wrote for insertion

2 Answers   SAP Labs,


explain about method overloading and method overriding with difficult examples

4 Answers  


Which of the following classes will have more memory allocated?

0 Answers  


how to minimize the functionality to will not force garbage collector?

2 Answers  


How to overcome the exception object reference not set to an instance of object?

0 Answers   Wipro,






Is set thread safe java?

0 Answers  


Why does java doesnot support multiple inheritance?

5 Answers   TCS,


why do we use interface in java?

5 Answers  


What is string args [] in java?

0 Answers  


what is the messsage u r going to get from an objectoriented programing?

0 Answers   MGL,


How do you create a bulleted list?

0 Answers  


What is this keyword in java?

0 Answers  


Categories