1.java?数组数组???Դ??
2.java数组来编写
3.JAVA编写源代码,要求使用数组存储一年12个月份的天数,并按顺序输入
java????Դ??
public class Test {
public static void main(String[] args) {
int[] arr1 = new int[5];
int[] arr2 = new int[5];
// 初始化数组
for (int i = 0; i < 5; i++) {
arr1[i] = i;
arr2[i] = i + 3;
}
// 输出复制前两个数组
System.out.println("\n复制前两个数组: ");
for (int i = 0; i < 5; i++) {
System.out.print(arr1[i] + " ");
}
System.out.println();
for (int i = 0; i < 5; i++) {
System.out.print(arr2[i] + " ");
}
// arr1 0~3复制到arr2
for (int i = 0; i < 4; i++) {
arr2[i] = arr1[i];
}
System.out.println("\n复制后两个数组: ");
// 输出复制后两个数组
for (int i = 0; i < 5; i++) {
System.out.print(arr1[i] + " ");
}
System.out.println();
for (int i = 0; i < 5; i++) {
System.out.print(arr2[i] + " ");
}
}
}
java数组来编写
fangfa1(){
List list = [8,4,2,1,,,];
int he =0;
for(int i=0;i<list.size();i++){
//循环输出数列的值
system.out.println(list.get(i));
//求数列中所有数值的和
he = he+list.get(i);
}
//输出数列中所有数值的和
system.out.println(he);
}
//从键盘中任意输入一个数据,判断数列中是源码源码remap 源码否包含此数。
//调用find() ,解析吾爱源码b站返回true --->在;返回false --->不在
private Boolean find (int m){
List list = [8,数组数组粒子人互动源码4,2,1,,,];
for(int i=0;i<list.size();i++){
if(m == list.get(i)){
return true;
}
}
return false;
}
//使用冒泡排序法从小到大排序该数列。
private void fangfa2(){
List list = [8,源码源码智云家政源码4,2,1,,,];
int tmp=0;
for(int j=0;j<list.size();j++){
int first = list.get(j);
for(int i=0;i<list.size();i++){
int second = list.get(i);
if(first<second){
tmp = first;
first = second;
second =tmp;
}
}
}
}
JAVA编写源代码,要求使用数组存储一年个月份的天数,并按顺序输入
代码如下:import java.util.Scanner;public class App {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int[] months = new int[];
for (int i = 0; i < months.length; i++) {
months[i] = scanner.nextInt();
}
for (int i = 0; i < months.length; i++) {
System.out.println((i + 1) + "月有" + months[i] + "天");
}
}
}
运行结果: