Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

'Int cannot be dereferenced' error

807588Mar 29 2009 — edited Mar 29 2009
Greetings,

I've been wrestling with this all day, trying to get this program to run. The problem seems to be in the final loop but i've tried everything and need a nudge in the right direction.

Heres the code:
package Lab;
import java.util.Scanner;

public class Shifter {
    
    Scanner input = new Scanner(System.in);
    int data[] = new int [ 15 ];

    public Shifter ( int size )
    {
    for ( int counter = 0; counter < data.length; counter++ )
         data[ counter ] = 1 + counter; 
    }
    
    public int shift( int pos )
    {
    int count = 0;
    
    for(count = 0; count < data.length; count++)
        data[ count ] = data[ count + pos ];
    return data[ count ];
    }
    
    public void display()
    {
    System.out.printf("Array contents: ");
    int pos = 0;
    
        int value = 0;    
        for(value = 0; value < data.length; value++)
        System.out.printf("%d", data[ value ] );
                      
        System.out.println();
        
        System.out.print("Shift how many positions? ");
        pos = input.nextInt();
            
                do{
                    System.out.println();
                    shift( pos );
                        for(value = 0; value < data.length; value++)
                        System.out.printf("%d", data[ value ]); 
                    
                    System.out.print("Shift how many positions? ");
                    pos = input.nextInt();          
            
               }while (! pos.matches("[-]?\\d+"));
       
        
    
    }
}
The final line in the condition statement is where the problem is, I think. I have to use a do/while loop for this assignment, so it can't be a for loop or a while. I want it to exit when something nonnumeric is entered.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 26 2009
Added on Mar 29 2009
7 comments
465 views