首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Java:无限循环中的扫描器输入

Java:无限循环中的扫描器输入
EN

Stack Overflow用户
提问于 2018-06-08 03:42:09
回答 1查看 639关注 0票数 -2

我目前正在尝试编写一个简单的程序来测试字符串中的某些字符是否在它们应该在的位置。例如,正常的mm/dd/yy格式中的'/‘。但由于某些原因,我甚至无法通过扫描仪输入,因为它只是一直要求输入。我到处寻找,可以找到任何人与我有确切的问题,考虑到这是发生在只有一个独立的扫描仪。我对Java非常陌生,所以我认为这只是我的一个简单的错误,但我似乎就是搞不清楚,也不想浪费更多的时间。

代码语言:javascript
运行
复制
import java.util.Scanner;
public class Main {


    public static Character req = '/'; 

    public static boolean datecheck(String d){
        String hold = d; 
        String[] a = new String[1];
        Character one = hold.charAt(2);
        Character two = hold.charAt(5); 

        //check to make sure the "/" are where they need to be
        if(one.equals(req)&&two.equals(req)){
        return true; 
        }
        else
            return false; 
    }



public static void main(String[] args) {
    // TODO Auto-generated method stub
    Scanner input = new Scanner(System.in);
    System.out.println("welcome to the BrightSide Scheduler "
            + "\nplease input the day you wish to schedule:");
    String date = input.next();
    input.close();
    try{
    datecheck(date);
    }catch (NullPointerException e){
        System.out.println("didnt work");
    }

    if (datecheck(date)==true){
        System.out.print("Success");
    }
    else{
        System.out.println("fail");
    }
}

}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50749068

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档