竞赛讨论区 > 这题java还有办法更优化么?
头像
城职马保国
发布于 2020-11-03 12:25
+ 关注

这题java还有办法更优化么?

贴上我的代码 始终在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());
    }
}

全部评论

(1) 回帖
加载中...
话题 回帖

本文相关内容

等你来战

查看全部

热门推荐