coderbyte - 字符串中两个数字之间 有三个‘?’返回 true

字符串中两个数字之间 有三个‘?’返回 true

import java.util.*; 
import java.io.*;

class Main {  
  public static String QuestionsMarks(String str) { 
  
    // code goes here   
    /* Note: In Java the return type of a function and the 
       parameter types being passed are defined, so this return 
       call must match the return type of the function.
       You are free to modify the return type. */
        int len =str.length();
       boolean isFlag=false;
       for(int i=0;i<len;++i){
           char c = str.charAt(i);
           int n =(int)c;
           if(n >= 48 && n<=57){
               int s = n-48;
                for(int j=i+1;j<len;++j){
                        char c1= str.charAt(j);
                        int n1 = (int)c1;
                        if(n1>=48 && n1<=57){
                            int s1 = n1-48;
                            if(s1 + s == 10){
                                String v = str.substring(i+1,j);
                        //        System.out.print(v+" ");
                                int count =0 ;
                                for(int k=0;k<v.length();++k){
                                    if(v.charAt(k) == '?'){
                                        count++;
                                    }
                                }
                                if(count==3){
                           //         System.out.print(" && "); 
                                   isFlag=true;
                                }else {
                             //      System.out.print(" @@ "); 
                                    isFlag=false;
                                    return "false";
                                }
                                j=len;
                            }
                        }
                }
       }
       }
       if(isFlag)
       return "true";
    return "false";
  } 
  public static void main (String[] args) {  
    // keep this function call here     
    Scanner s = new Scanner(System.in);
    System.out.print(QuestionsMarks(s.nextLine())); 
  }   
} 
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 第5章 引用类型(返回首页) 本章内容 使用对象 创建并操作数组 理解基本的JavaScript类型 使用基本类型...
    大学一百阅读 3,272评论 0 4
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,993评论 19 139
  • 字符的 Unicode 表示法 codePointAt() String.fromCodePoint() 字符串的...
    卞卞村长L阅读 778评论 0 0
  • 五一三天假,褐锦打定了主意要好好休息一番,最近工作实在是太累了,几乎天天加班,很久没有好好地放松一下,喝喝茶水,看...
    褐锦阅读 741评论 4 4
  • 保持你的工具是最新的 Android工具包支持的构建往往是最新的,所以官方的一些建议和技巧往往都是针对于最新版本的...
    Terry阅读 1,123评论 0 50