I wrote a code for the problem http://ift.tt/1eOf6my , 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;
}
}
Aucun commentaire:
Enregistrer un commentaire