Having trouble calling a method to edit a string from another class in java

Bingoned

I've got a simple java program that is supposed to take the specified characters in a string and print them back out to the user by doing everything within a secondary method in a secondary class while taking input from the user in the first class.

The problem that I'm having is that when I try to invoke the secondary method in my main method, I get an error that says "The method copy(String) is unidentified for my main method.

My code for the main method is:

    System.out.println("Copying - Enter a string");
            String currentString = input.next();
            System.out.println("The current string is: " + currentString);
            System.out.println("Enter the starting position");
            int startPosition = input.nextInt();
            System.out.println("Enter one past the ending position");
            int onePastLastPosition = input.nextInt();
            System.out.println("The new string is: " + copy(currentString));

And for the copy method is:

public static String copy(String currentString, int startPosition, int onePastLastPosition) { 
        currentString = currentString.substring(startPosition, onePastLastPosition); 
        return currentString;
    }

So for example, what the code is supposed to do, is if I input a string "abcd", it returns back to me "bc", but the system gets hung up on the last line in the first method. Any help with understanding where I went wrong, and how to fix it in the future would be much appreciated.

Spectric

You didn't provide the method the necessary parameters for it to execute properly.

Method copy is accepting three parameters: currentString, startPosition, onePastLastPosition as per the parameters specified:

public static String copy(String currentString, int startPosition, int onePastLastPosition) {

So you should be calling the method like so:

System.out.println("The new string is: " + copy(currentString, startPosition, onePastLastPosition));

Test Run

Copying - Enter a string
spectric
The current string is: spectric
Enter the starting position
1
Enter one past the ending position
2
The new string is: p

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Having trouble calling a method from another class

Having trouble calling a method from inside another method

Having trouble referring to a method in another class

Having trouble calling this class

java calling a method from another class

Having trouble running a method from my SQLiteOpenHelper class in an Async task in another class

Ruby: trouble calling class instance from method

Calling Method of another class from Recursion Method: Java

Having an issue calling methods from another class

Having trouble calling a bash script from another bash script

Having trouble calling two variables from method into main C++

I am having trouble calling code from a class

Java cannot find symbol when calling a method from another class

calling MainActivty's method from another java class without onCreate

Java LIBGDX, Calling InputHandler's TouchDown method from another class

Java - Calling Boolean Method from another class with arraylist parameter

Calling method of Another class from run() method

Calling a method from another method in the same class

Calling a class from another class with main method

Calling a method from one class in another class

Having trouble passing values from one class to another

Trouble calling one method into another

Having trouble calling objective-c method

Having trouble calling aspx.cs method

Trouble calling NSOpenPanel from another class and attaching it to its parent window

calling another method from the main method in java

Calling a method from inside of another class

Calling a method of the MainActivity from another class?

Calling method from another class unsuccessful