在 Java 中创建一个大小为 x 的 String[] S 数组,添加一些值 init ,现在再创建两个数组 even[] 和 odd[],偶数数组应包含值 String S[] 和偶数索引号和 odd[]将包含具有奇数索引号的字符串 S[] 的值
package trying;
import java.util.Scanner;
public class ArrayTest {
public static void main(String[] args) {
int val;
int evcounter = 0;
int odcounter = 0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter total no of elements ");
val = sc.nextInt();
System.out.println("Enter values ");
String[] n = new String[val];
for (int i = 0; i < n.length; i++) {
n[i] = sc.next();
if (i % 2 == 0) {
evcounter++;
} else {
odcounter++;
}
if (evcounter + odcounter == val) {
String[] eve = new String[evcounter];
String[] odd = new String[odcounter];
System.out.println("******Please Help AFTER THIS**********");
}
}
}
}
预期输出:
Enter total no of elements
3
Enter Values
HI
hello
Bye
Even array:[HI,Bye]
ODD array :[hello]
杨__羊羊
郎朗坤
富国沪深
相关分类