I'm New to Java

My first semester, having some trouble with a particular assignment.

My program compiles fine,

publicclass NewYork

{

publicstaticvoid main(int street,int avenue){

if(street < 0 || avenue < 0){

System.out.println("Invalid. Usage: NewYork <streetaddress><avenue>");

}

else{

int x = street/10;

int y = x/2;

int fstreet = 0;

if(avenue == 1){

fstreet = y + 3;}

if(avenue == 2){

fstreet = y + 3;}

if(avenue == 3){

fstreet = y + 10;}

if(avenue == 4){

fstreet = y + 8;}

if(avenue == 5){

fstreet = y + 13;}

if(avenue == 6){

fstreet = y - 12;}

if(avenue == 7){

fstreet = y + 12;}

if(avenue == 8){

fstreet = y + 10;}

if(avenue == 9){

fstreet = y + 13;}

if(avenue == 10){

fstreet = y + 14;}

System.out.println("The nearest cross street number is " + fstreet);

}

}

}

Ignore the random math, its just the assignment.

But, when I try to run it, I get this error message.

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

What do I need to do?

[2715 byte] By [sjmclean7a] at [2007-11-26 20:01:36]
# 1

Your main method is wrong.

Check the tutorial in sun homepage.

The main method in java must be

public static void main(String[] args){}

You see the difference?

lupansanseia at 2007-7-9 23:00:14 > top of Java-index,Java Essentials,New To Java...
# 2

It's specified I have to use command line arguments...so

public static void main(String [] args)

and then

int street = args[0]

int avenue = args[1]

but it won't accept the arguments as integers. I tried casting them with (int) and that didn't work either.

sjmclean7a at 2007-7-9 23:00:14 > top of Java-index,Java Essentials,New To Java...
# 3

How did you do that?

String street = args[0];

String avenue = args[1];

int str = Integer.parseInt(street)

int ave = Integer.parseInt(avenue);

I would leave it to you to figure out what will happen if no parameters are passed to program and if the parameters are NAN.

lupansanseia at 2007-7-9 23:00:14 > top of Java-index,Java Essentials,New To Java...
# 4
Ah great thanks, I've got it working now. Thanks to everyone who helped.Stephen
sjmclean7a at 2007-7-9 23:00:14 > top of Java-index,Java Essentials,New To Java...
# 5
Just to kick you along the learning curve, change all those if statements into a series of if/else if statements.
floundera at 2007-7-9 23:00:14 > top of Java-index,Java Essentials,New To Java...