小编Jac*_*ack的帖子

如何在Java中从一个字符串复制到另一个字符串?

我有两个字符串str1和str2。我正在尝试使用charAt将某些字母从一个字符串复制到另一个字符串。我知道我可以使用字符串复制,但是我想要一些字符而不是全部。

如何将subString从一个字符串复制到Java中的另一个字符串?

public class MyServerSide {

    public static void main(String[] args) {
        String str1 = "Hello World!;
        String str2;
        for (int 1=0; i < str1.length(); i++){
            if (i>=3){
                str2.charAt(i) = str1.charAt(i);//Here is the problem. It gives me an error
                                                //Saying that the left argument must be a 
                                                //variable

            }//End of if statement
        }//End of for loop
    }//End of main method
}//End of class
Run Code Online (Sandbox Code Playgroud)

java string substring charat

2
推荐指数
1
解决办法
6万
查看次数

何时这个for循环的条件会变为false?

我正在研究我的C++练习题,为即将到来的测试做准备,我正在努力解决以前从未见过的for循环问题.

        for (int i = 0; s[i]; i++)
Run Code Online (Sandbox Code Playgroud)

s从主要发送的字符串是"Two roofs to fix"

问题是for循环的条件何时会变为false?

c++ logic

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

这在c ++中.它是如何工作的?

我对我的C++作业有疑问.我只是对此感到困惑.

下面的代码是我的.

我的问题是为什么=运算符中的if语句中的条件为真?

#include <cstring>
class abc {
      char p[9];
      int inc;
   public:
      abc( ) { inc = 8; strcpy(p, "10010101"); }
      ~abc( );
      abc& operator=(const abc &);

};

abc::~abc( ) {

}
abc& abc::operator=(const abc &c) {
   if(this != &c) { //my question is why this condition is true?
      inc = c.inc - 2;
      for(int i=0; i<inc; i++) {
     p[i] = c.p[i] + 2;
      }
   }
   return *this;
}

int main( ) {
   abc x, y;
   x = y; …
Run Code Online (Sandbox Code Playgroud)

c++ this

0
推荐指数
1
解决办法
170
查看次数

分配后我在哪里可以释放内存?

我正在尝试做一些内存分配练习.

我有下面的代码,但有两个问题.

在分配后,我在哪里必须使用delete []来释放内存?

使用show()函数时,为什么此代码的输出功能是CDcar?.

#include <cstdlib>
#include <new>
#include <iostream>
#include <cstring>
using namespace std;

class automobile {

    private:

        char (*function)[30];
        char *type;
        double speed;

    public:

        automobile ( );
        automobile (double , char *);
        void speed_up (double);
        void speed_down(double);
        const char * get_function ( ) const;
        void show ( );

};

automobile::automobile ( ) {

    speed = 0;
    function = new char [1][30];
    strcpy(function[1], "CD player with MP3");

    type = new char [4];
    strcpy(type, "car");

}

automobile::automobile(double spd, char …
Run Code Online (Sandbox Code Playgroud)

c++

0
推荐指数
1
解决办法
193
查看次数

标签 统计

c++ ×3

charat ×1

java ×1

logic ×1

string ×1

substring ×1

this ×1