I want to call a user defined function inside a function without creating an object or passing any value to the called function. Is there any possible way to do that? consider the following code
import java.io.*;
public class sorting
{
int number[]=new int[5];
void input()throws IOException
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter 5 numbers");
for(int i=0;i<5;i++)
{
number[i]=Integer.parseInt(in.readLine());
}
}
void sort()
{
int no;
for(int i=0;i<5-1;i++)
{
for(int j=i+1;j<5;j++)
{
if(number[j]<number[i])
{
no=number[i];
number[i]=number[j];
number[j]=no;
}
}
}
}
void display()
{
for(int i=0;i<5;i++)
{
System.out.print(number[i]+"\t");
}
}
public static void main()throws IOException
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
sorting o1=new sorting();
o1.input();
o1.sort();
o1.display();
}
}
this is a code for sequential sort. in void main i've created an object o1 and called the methods. but instead of calling 3 methods i want my job to be done by calling just one of them. by my knowledge that can be done by calling a function inside another function.
staticmethod