Code:
import java.util.Scanner;

public class SuffixArray{
   public static void main(String[] args){
      Scanner stdIn = new Scanner(System.in);
      String string1;
      String[] array1;
      int a;
      System.out.print("String: ");
      string1 = stdIn.nextLine();
      a = string1.length();
      for (int i=0; i<=a; i++){
         array1[i] = string1.substring(i);}
      array1.sort();
      for (int i=0; i<=array1.length; i++){
         System.out.println(array1[i]);}
      }}


When I attempt to compile this I get the following error:


Code:
cannot find symbol
array1.sort();
      ^
symbol: method sort()
location: variable array1 of type String[]


What am I doing incorrectly?

Edit by Merth: Moved to the General Programming sub forum.
According to the Arrays class documentation Arrays.sort is a static (rather than instance) method, so try:

Code:
Arrays.sort(array1);
It returns this:


Code:
cannot find symbol
Arrays.sort(array1);
^
symbol: variable Arrays
location: class SuffixArray


If I comment out that line it says array1 wasn't initialized, and if I change it to the following it asks for an array dimension.


Code:
array1 = new String[];


If I add any number as the dimension, it returns an error of not finding the variable array1.
The Java compiler isn't sure where to find "Arrays" - you need to show it that you mean java.util.Arrays by adding

Code:
import java.util.Arrays;

to the top of your source file.
benryves wrote:
The Java compiler isn't sure where to find "Arrays" - you need to show it that you mean java.util.Arrays by adding

Code:
import java.util.Arrays;

to the top of your source file.


In many cases your life will be made easier by

Code:
import java.util.*;
I got all the errors worked out. Thanks for the assistance.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement