在Java中添加字符

huangapple 未分类评论44阅读模式
英文:

Adding characters in Java

问题

以下是您要求的翻译内容:

如何将相同的方法用字符表示,如果它在字符串中。例如,给出如下的Increase方法。

 String a;

 public boolean increase(String b){

 if(a.length() > 0)
 this.a = this.a + b;

return true;
}

我想写一个类似的方法。

String a;
char[] achar = a.toCharArray();

public boolean increase(String b){
char[] bchar = b.toCharArray();
if(a.length() > 0){
for(i = 0; i < a.length(); i++){
achar[i] = (char)(achar[i] + bchar[i]);
}
achar[i] = (char)(achar[i] + bchar[i]);
return true;
}

}

如果String a = "Concat",String b = "Method"。
如果为真;
输出将会是:Concat Method。

英文:

How to write same method in characters if it is in strings.For example Increase method given below.

 String a;

 public boolean increase(String b){

 if(a.length() &gt;0)
 this.a = this.a + b;

return true
}

I want to write same method something like.

String a ;
char[] achar = a.tochararray()

public boolean increase(String b){
char[] bchar = b.tochararray();
if(a.length() &gt;0){
for(i =0; i &lt; a.length();i++){
achar[i] = achar[i] + bchar[i];
}
achar[i] = achar[i] + bchar[i];
return true;
}

If String a = "Concat", String b = "Method".
if true;
output be like: Concat Method.

答案1

得分: 0

我不确定你在问什么。

if (a.equals("联系方式") && b.equals("方法"))
{
    String wholeSentence = a + " " + b;
    char[] sentenceInCharArray = wholeSentence.toCharArray();
}
英文:

I'm not sure what you asking for.

if( a.equals(&quot;Contact&quot;) &amp;&amp; b.equals(&quot;Method&quot;) )
{
    String wholeSentance = a + &quot; &quot; + b;
    char[] sentanceInCharArray = wholeSentance.toCharArray();
}

huangapple
  • 本文由 发表于 2020年7月24日 00:33:22
  • 转载请务必保留本文链接:https://java.coder-hub.com/63058999.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定