0

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

Edited by Genericusername: n/a

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Genericusername
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 (...
Votes + Comments
Prompt, Helpful, and Concise
0

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!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.