package practice;
public class ArrayElementsAddIndices {
public static void main(String[] args) {
int array[] = { 5, 4, 3, 2, 1, 6, 7, 8, 9 };
System.out.println("原数组中的元素:");
for (int i = 0; i < array.length; i++) {
System.out.print(array[i] + " ");
}
for (int i = 0; i < array.length - 1; i++) {
for (int j = i + 1; j < array.length; j++) {
if (array[i] > array[j]) {
int temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
System.out.println("\n\n数组元素选择排序:");
for (int i = 0; i < array.length; i++) {
System.out.print(array[i] + " ");
}
System.out.println("\n\n数组元素及其对应下标:");
for (int i = 0; i < array.length; i++) {
System.out.println(array[i] + " —— " + i);
}
int newArray[] = new int[array.length];
System.out.println("\n原数组元素加上对应下标后生成的结果元素:");
for (int i = 0; i < newArray.length; i++) {
System.out.print((newArray[i] = array[i] + i) + " ");
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/183217.html原文链接:https://javaforall.cn