class bubbleSort1{


public static void bubbleSort(int[] x) {
int n = x.length;
for (int pass=1; pass < n; pass++) { // count how many times
// This next loop becomes shorter and shorter
for (int i=0; i < n-pass; i++) {
if (x > x[i+1]) {
// exchange elements
int temp = x; x = x[i+1]; x[i+1] = temp;
}
}
}
}
}
the output say..

java.lang.NoSuchMethodError: main
Exception in thread "main"

Recommended Answers

All 7 Replies

class bubbleSort1{


public static void bubbleSort(int[] x) {
int n = x.length;
for (int pass=1; pass < n; pass++) { // count how many times
// This next loop becomes shorter and shorter
for (int i=0; i < n-pass; i++) {
if (x > x[i+1]) {
// exchange elements
int temp = x; x = x[i+1]; x[i+1] = temp;
}
}
}
}
}
the output say..

java.lang.NoSuchMethodError: main
Exception in thread "main"

The class that you're trying to run doesn't have an entry point (main) method.

Try declaring this method in your class--

public static void main(String[] args){


}

-- also please use code tags.

in your programeme no main function
so youcan compile it
bu u can't run that programme
see syntax

import java.io.*;
class bubbleSort1{
public int x[],max;


public void input()throws IOException
{
DataInputStream in=new DataInputStream(System.in);
System.out.println("Enter the Limit:");
max=Integer.parseInt(in.readLine());
x=new int[max];
for (int pass=0; pass <max; pass++)
{
System.out.print("Enter the value for "+pass+" element :" );
x[pass]=Integer.parseInt(in.readLine());
}
}


public void bubbleSort() {

for (int pass=0; pass < max; pass++) {
for (int i=1; i < max-pass; i++) {
if (x[i-1] > x) {
// exchange elements
int temp = x[i-1]; x[i-1] = x; x = temp;
}
}
}
}


void result()
{
for (int pass=0; pass < max; pass++)
{
System.out.println(x[pass]);
}
}


public static void main(String agr[])
{

bubbleSort1 obj= new bubbleSort1();
try
{
obj.input();
obj.bubbleSort();
obj.result();
}
catch(Exception e)
{System.out.println(e);}
}
}


In ur coding there is no main method thats wy that problem occured.

import java.io.*;
class bubbleSort1{
public int x[],max;


public void input()throws IOException
{
DataInputStream in=new DataInputStream(System.in);
System.out.println("Enter the Limit:");
max=Integer.parseInt(in.readLine());
x=new int[max];
for (int pass=0; pass <max; pass++)
{
System.out.print("Enter the value for "+pass+" element :" );
x[pass]=Integer.parseInt(in.readLine());
}
}


public void bubbleSort() {

for (int pass=0; pass < max; pass++) {
for (int i=1; i < max-pass; i++) {
if (x[i-1] > x) {
// exchange elements
int temp = x[i-1]; x[i-1] = x; x = temp;
}
}
}
}


void result()
{
for (int pass=0; pass < max; pass++)
{
System.out.println(x[pass]);
}
}


public static void main(String agr[])
{

bubbleSort1 obj= new bubbleSort1();
try
{
obj.input();
obj.bubbleSort();
obj.result();
}
catch(Exception e)
{System.out.println(e);}
}
}


In ur coding there is no main method thats wy that problem occurred.

congrats
there is no error
its succesfully running

oh! very nice that your programme is properly running.what did happen to this.

commented: Do not post useless comments just to spread your sig links around. -2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.