贴上我的代码 始终在while判断上不给过,往大佬能给点建议.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class P_30 {
static BufferedReader reader;
static StringTokenizer tokenizer;
static Integer num ;
public static void main(String[] args) throws IOException {
reader = new BufferedReader(new InputStreamReader(System.in));
tokenizer = new StringTokenizer("");
while ((num=P_30.nextInt())!=null) {
int n[] = new int[num];
boolean bool = false;
for (int i = 0; i < num; i++) {
n[i]=P_30.nextInt();
}
int m = P_30.nextInt();
int count = 0;
for (int i = 0; i < num; i++) {
if (n[i]==m) {
bool=true;
break;
}
count++;
}
if (bool) {
System.out.println(count);
}
else {
System.out.println("No");
}
num = null;
}
}
static String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
}
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class P_30 {
static BufferedReader reader;
static StringTokenizer tokenizer;
static Integer num ;
public static void main(String[] args) throws IOException {
reader = new BufferedReader(new InputStreamReader(System.in));
tokenizer = new StringTokenizer("");
while ((num=P_30.nextInt())!=null) {
int n[] = new int[num];
boolean bool = false;
for (int i = 0; i < num; i++) {
n[i]=P_30.nextInt();
}
int m = P_30.nextInt();
int count = 0;
for (int i = 0; i < num; i++) {
if (n[i]==m) {
bool=true;
break;
}
count++;
}
if (bool) {
System.out.println(count);
}
else {
System.out.println("No");
}
num = null;
}
}
static String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
}
全部评论
(1) 回帖