中软面试题(二)

news/2024/7/4 1:45:24 标签: 中软, 面试, string, class
class="baidu_pl">
class="article_content clearfix">
class="htmledit_views">

        要求:有一个不定长度的String,其中前面是字母,后边是数字,例如:"abcd123.456",  要求写一个方法得到其中的数字以String的形式返回,数字保留小数点后两位,不四舍五入,截去多余小数。例如:"abcd123.456",得到"123.45"  如果数字没有小数点,要得到两位为0的小数,例如:"abcd123",得到"123.00"。

       程序如下:
public class Test {
       public static void main(String[] args) {
       String str="abcd123.345";
       System.out.println(getString(str));
        }
       public static String getString(String str){
             String getNumber;
             getNumber=str.replaceAll("[a-z|A-Z]", "");
             if(getNumber.indexOf(".")==-1){
                     getNumber=getNumber+".00";
             }
             else{
                   if(getNumber.indexOf(".")==getNumber.length()-1){
                           getNumber=getNumber+"00";
                   }else if(getNumber.indexOf(".")==getNumber.length()-2){
                           getNumber=getNumber+"0";
                   }else{
                           getNumber=getNumber.subclass="tags" href="/tags/STRING.html" title=string>string(0, getNumber.indexOf(".")+3);
                   }
   
          }
          return getNumber;
     }
}

 

 

      


http://www.niftyadmin.cn/n/1759639.html

相关文章

LeetCode 427 Construct Quad Tree 解题报告

题目要求 We want to use quad trees to store an N x N boolean grid. Each cell in the grid can only be true or false. The root node represents the whole grid. For each node, it will be subdivided into four children nodes until the values in the region it rep…

Spring注解开发 - Aop原理

1. AOP AOP的使用 2. 原理 对于这类的源码分析,主要就是看往容器中注入了什么组件和组件什么时候工作 EnableAspectJAutoProxy注解 Aop要起作用关键的一点在于配置EnableAspectJAutoProxy注解,所有先来分析这个注解 点进这个注解,可以看…

中软面试题-最新

中软的面试比较经典,也比较严格,一般有四轮,类似于微软的面试。中软面过以后,根据项目组,会推到美国微软那边运用live meeting & con-call 再面一次。以下是我的面试题及个人的小分析,拿出来和大家shar…

python的Web框架,中间件middleware及djangoAdmin

简介 用于处理request和response的中间处理的函数,可以创建在项目中的任意位置,只要可以导入即可。 建议创建在APP目录下,方便管理。 函数范式与激活 1 中间件的范式:2 3 # 必须接受get_response这个餐参数4 def simple_middlewar…

平面图转对偶图19_03_21校内训练 [Everfeel]

对于每个平面图,都有唯一一个对偶图与之对应。若G‘是平面图G的对偶图,则满足: G中每一条边的两个节点对应着G中有公共边的面,包括最外部无限大的面。 直观地讲,红色标出来的图就是蓝色标出的图的对偶图。 求出一个平面…

Spring - 设计理念和整体架构

1. 设计理念 Spring为开发者提供一站式的轻量级应用开发框架 在Java EE的应用开发中,支持POJO和使用JavaBean的开发方式,使应用面向接口开发,充分支持OO的设计方法 从设计上,Spring分为核心,组件和应用三个基本的层…

LeetCode 706 Design HashMap 解题报告

题目要求 Design a HashMap without using any built-in hash table libraries. To be specific, your design should include these functions: put(key, value) : Insert a (key, value) pair into the HashMap. If the value already exists in the HashMap, update the val…

秒转换成年月日时分秒 和复制文本到剪贴板

秒转换成年月日时分秒 getDateStr (seconds) {let date new Date(seconds)let year date.getFullYear()let month date.getMonth() 1let day date.getDate()let hour date.getHours() < 10 ? 0 date.getHours() : date.getHours()let minute date.getMinutes() <…