简体   繁体   中英

Undefined Method error in Java SE

I wrote a code for the problem http://www.spoj.com/problems/PRIME1/ , what this code does is that it takes input in string then splits it whith split() into two integers stored un an array this array is then returned to main, where it is checked for prime using prime() within the given indexes, errors are I am using Eclipse. errors are:Exception in thread "main" java.lang.Error: Unresolved compilation problems: The method input(String) is undefined for the type PrimeGenerator The method input(String) is undefined for the type PrimeGenerator The method split(String) is undefined for the type PrimeGenerator The method prime(int) is undefined for the type PrimeGenerator

at PrimeGenerator.main(PrimeGenerator.java:10)

here goes the code :

import java.io.*;
import java.lang.*;
public class PrimeGenerator {

public static void main(String args[])throws IOException{

  PrimeGenerator obj=new PrimeGenerator();

  System.out.println("enter number of test cases");
  String test_case=""; test_case=obj.input(test_case); 
  int test_case_val=Integer.parseInt(test_case);
  String array[]=new String[test_case_val];

  for(int i=0;i<test_case_val;i++){
    array[i]=obj.input(array[i]);

  }

  System.out.println();

  for(int z=0;z<test_case_val;z++){
    int[] copy=obj.split(array[z]);

    for(int s=copy[0];s<copy[1];s++){
        if(prime(s)==1){
            System.out.println(s);
        }

        System.out.println();
    }
  }

}


public String Static input(String x)throws IOException{
    InputStreamReader isr = new InputStreamReader(System.in);
    BufferedReader br = new BufferedReader(isr);

    x=br.readLine(); return x;
}


int[] Static split(String x[]){
    String one=""; String two="";
    int length=x.length();
    for(int k=0;k<length;k++){
        if(x.charAt(k)=' '){
            one=x.substring(0,k-1); two=x.substring(k+1,length-1);
        }
    }
    int open=Integer.parseInr(one);
    int close=Integer.parseInr(two);

    int[] arrax={open, close}
    return arrax[];
}





int Static prime(int x){
    int flag=0;
    for(int temp=1;temp<=x;temp++){
        if(x%temp==0) flag++;
        else continue;
    }
    if(flag==2) return 1;
    else return 0;
    }





}  
public String Static input(String x)throws IOException{

This is not Java. Static is not uppercase and should go before the return type and so your code does not see any "input" method there, thus the error. It should read...

public static String input(String x) throws IOException {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM