我如何提取字符串[]或arraylist中的所有元素,并将所有单词与它们之间的适当格式(具有单个空格)组合并存储在数组中.
String[] a = {"Java", "is", "cool"};
Run Code Online (Sandbox Code Playgroud)
输出:Java很酷.
我需要帮助来确定如何从字符串中删除重复字符.它必须以递归方式完成,这才是真正的问题.
public class FEQ2 {
/**
* @param args
*/
public static void removeDups(String s, int firstChar, int secondChar) {
if (s.length() == 1) {
System.out.println(s);
}
char a = s.charAt(firstChar);
if (a == s.charAt(secondChar)) {
s = a + s.substring(secondChar + 1);
}
System.out.println(s);
removeDups(s, firstChar + 1, secondChar + 1);
//return s;
}
public static void main(String[] args) {
//System.out.println(removeDups("AAAABBARRRCC", 1));
removeDups("AAAABBARRRCC", 0 , 1);
}
}
Run Code Online (Sandbox Code Playgroud) 使用递归如何更新局部变量直到满足条件.我在下面有一个实例解释了为什么问题很好.count变量是一个局部变量,并且方法经过计数的时间设置为0.我不能将方法移动到方法之外它必须是局部变量而不是静态或其他任何东西..所需的输出应该是(3 6) )
public static int returnInt(int b) {
int count = 0;
if (b == 6) {
System.out.println(count + " " + b);
}
b += 2;
count++;
return returnInt(b);
}
Run Code Online (Sandbox Code Playgroud) 我如何从二维数组中提取数据.. e 和 b 是数组的索引
int e = IO.readInt();
int b = IO.readInt();
int a[][] = { { 8, 2, 6, 5 }, // row 0
{ 6, 3, 1, 0 }, // row 1
{ 8, 7, 9, 6 } };
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[0].length; j++) {
a[i][j] = i;
System.out.print(a[i][j] + " ");
}
System.out.println("");
}`enter code here`
Run Code Online (Sandbox Code Playgroud)