Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Keep up the very good job that you and your team are doing. This site has replaced my morning cup of tea as a must have/do!!!..."

Geography

Where in the world do Tek-Tips members come from?

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

csphard (Programmer)
15 Jul 12 0:33
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[i]);

String myout;
myout = myInfo[i];
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); }
}
feherke (Programmer)
15 Jul 12 5:12
Hi

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

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

Feherke.
http://feherke.github.com/

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close