小编PVP*_*PVP的帖子

为什么我们不为短类型添加"s"后缀?

为什么我们s不像short s = 2s;我们用float写的那样用短数据类型写float f = 1.23f

我知道当我们float默认编写时,编译器会将其视为double并为其分配8个临时字节,当它尝试将该8字节复制到float4时会导致类型错误,这就是我们f在初始化之后编写的原因float,但是为什么我们不做short默认的类似的东西int是文字类型?

java

7
推荐指数
2
解决办法
1304
查看次数

检查两个字符串是否相互排列?

我正在解决这个问题作为学校的任务.但是当我提交代码时,我的两个测试用例出错了?我不知道出了什么问题.我检查了各种其他测试案例和角落案例,一切正确.

这是我的代码:

    public static boolean isPermutation(String input1, String input2) {

       if(input1.length() != input2.length())
       {
           return false;
       }

       int index1 =0;
       int index2 =0;
       int count=0;


       while(index2<input2.length())
       {

           while(index1<input1.length())
           {
               if( input1.charAt(index1)==input2.charAt(index2) )
               {
                   index1=0;
                   count++;
                   break;
               }
             index1++;     

           }
           index2++;
       }


       if(count==input1.length())
       {
           return true;
       }


       return false;

}
Run Code Online (Sandbox Code Playgroud)

样本输入

abcde
baedc
Run Code Online (Sandbox Code Playgroud)

产量

true
Run Code Online (Sandbox Code Playgroud)

样本输入

abc
cbd
Run Code Online (Sandbox Code Playgroud)

产量

false
Run Code Online (Sandbox Code Playgroud)

java

3
推荐指数
1
解决办法
2585
查看次数

标签 统计

java ×2