拂晓的镇魂歌 2014-03-08 13:42 采纳率: 0%
浏览 3742

很简单的,求教为何java程序跳不出cin.hasnext()循环

import java.util.*;
public class Main {
public static void main(String[] args){
ArrayList num=new ArrayList();
Scanner cin=new Scanner(System.in);
int n=0;
int a,b,c;
while(cin.hasNext()){
String str="",str1="";
str=cin.nextLine();

        for(int i=0;i<str.length();i++){
            if(str.charAt(i)!='+'&&str.charAt(i)!='-'&&str.charAt(i)!='='){
                str1+=String.valueOf(str.charAt(i));
                if(num.size()%3==2){
                    num.add(str1);
                    str1="";

                }
            }
            else{
                num.add(str1);
                str1="";
            }

        }


        System.out.println(num);


    }
    System.out.println("nihao");
    /*for(int j=0;j<num.size()-2;){
        System.out.println(j);
        a=Integer.valueOf(num.get(j));
        b=Integer.valueOf(num.get(++j));
        c=Integer.valueOf(num.get(++j));
        ++j;
        //System.out.print(b);System.out.print(c);
    if(a+b==c||a-b==c){
        n++;

    }
    }*/
}

}

  • 写回答

1条回答

  • JonsonJiao 2015-07-14 04:55
    关注

    cin.hasNext()会一直在等待你输入,不会跳出的。

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog