Hello,

I'm writing a program that creates repetitions of a section of a word.
I'm trying to get the program to evaluate the data i send to the tester method, and return true or false depending on whether or not it is a valid input.

import java.util.Scanner;
                                                                                             
public class WordRepeater
{
		public static void main (String []args)
		{
			Scanner input = new Scanner(System.in);
			System.out.println( "please input a word with an even number of letters" );
			String word = input.nextLine();
			System.out.println("please an even number less that or equal to twenty");
			int reps = input.nextInt();
			System.out.print( word); 
			System.out.println( reps); 
			boolean pass = tester(word, reps);
			//System.out.print( pass ); 
		}
		
		public boolean tester (String Word1, int Reps1)
		{
			boolean check = true;
			if (Word1.length() % 2 == 0) {}
			else if (Word1.length() % 2 != 0) check = false;
			
			if (Reps1 % 2 == 0) {}
			else if (Reps1 % 2 != 0) check = false;
		
			return check;
			}
			
}

However, i get am error saying that the non-static method tester cannot be referenced from a static context.

I'm out of practice in java, having not done it the last half- year, so i cannot figure oiut where i went wrong.

any advice would be well appreciated

Recommended Answers

All 2 Replies

If you wish to access the method without an instance of your WordRepeater class, you will need to declare the tester method 'static'.

public static boolean tester (...
commented: Prompt, Helpful, and Concise +1

If you wish to access the method without an instance of your WordRepeater class, you will need to declare the tester method 'static'.

public static boolean tester (...

Silly error! thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.