Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question why method works in 1 spot and not in the other

Status
Not open for further replies.

csphard

Programmer
Apr 5, 2002
194
US
I want to know why the following method works at one location and not at the other.

I am new to Java and trying to lear it

// works here why
public static String mysub(String info)
{ return ("test sub is " + info); }


ENTIRE CODE
public class MyTest {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

int howmany = args.length;
String[] myInfo = new String[howmany];


for (int a = 0 ; a < howmany; a++)
{
myInfo[a] = args[a]; //"Howard";
}


System.out.println(" Number of args = " + howmany);




for (int i = 0 ; i < howmany; i++)
{
System.out.println("Item" + i + " " + myInfo);

String myout;
myout = myInfo;
if (myout.equals("Howard")) {
System.out.println("Hey Howardppp");
System.out.println(mysub(myout));
}

if (myout.equals("Tony")) {
System.out.println("Hey Tony");
}
// or with null-safe Soda condition
// if ("Howard".equals(myout)) {
// System.out.println("Hey Howardppp");
// }
//System.out.println("myout=" + myout);

// Does not work here
//public static String mysub(String info)
//{ return ("test sub is " + info); }

}

System.out.println("end");


}
// works here why
public static String mysub(String info)
{ return ("test sub is " + info); }
}
 
Hi

In Java you can not place a method declaration inside another method declaration.

Next time please indent your code and post it between [tt][ignore]
Code:
[/ignore][/tt] and [tt][ignore]
[/ignore][/tt] TGML tags. Will not read such code soup again.

Feherke.
[link feherke.github.com/][/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top