标签:lis break 说明 list 否则 存在 输出 linear package
package com.ahabest.array;
public class ArratTest {
public static void main(String[] args) {
// 一维数组的创建
char []arrc = new char[6];
String []arrs = new String[6];
//一维数组的赋值
arrc[0] = ‘a‘;
arrc[1] = ‘b‘;
arrs[0] = "aa";
arrs[5] = "ee";
//一维数组的创建及赋值
int []arri = {1,2,3,4,5,6};
double []arrd = {1.0,2.0,3.0,4.0,5.0,6.0};
//一维数组的循环遍历输出
for(int i=0;i<arrc.length;i++) {
System.out.print(arrc[i]+" ");
}
System.out.print("\n");
for(int j=0;j<arrs.length;j++) {
System.out.print(arrs[j]+" ");
}
System.out.print("\n");
for(int m=0;m<arri.length;m++) {
System.out.print(arri[m]+" ");
}
System.out.print("\n");
for(int n=0;n<arrd.length;n++) {
System.out.print(arrd[n]+" ");
}
}
}
import java.util.Scanner;
public class LinearArray {
public static void main(String[] args) {
System.out.println("请输入一个整数:");
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
String arr[] = new String[i];
System.out.print("请换行输入");
System.out.print(i);
System.out.println("个字符串:");
for(int a=0;a<arr.length;a++){
arr[a] = sc.nextLine();
}
for(int b=0;b<=arr.length-1;b++){
System.out.println(arr[b]);
}
}
}
//写程序读入十个整数,然后输出这些整数,如果某整数出现多次,那么只输出一次。
package com.ahabest.array;
import java.util.Scanner;
public class $_Sort {
public static void main(String args[]){
int []number = new int[10];
Scanner in = new Scanner(System.in);
System.out.print("请输入十个数:\n");
for (int i = 0;i<10;i++){
number[i] = in.nextInt();
}
System.out.println("输出的结果为:");
System.out.print(number[0]);
for (int i=1;i<10;i++){
boolean b=true;
for(int j=0;j<i;j++){
if (number[i] == number[j])
b=false;
}
if(b == true){
System.out.print(" "+number[i]);
}
}
}
}
//1.计算一维数组的元素和与平均值
public class TheAverageValue {
public static void main(String[] args) {
double in[] = {23,45,65,78,56};
double sum = 0d;
for(int i=0;i<in.length;i++){
sum += in[i];
}
System.out.println(sum);
System.out.println(sum/in.length);
}
}
//2.有一个整数数组请将该序列倒序存放并输出
public class FlashBack {
public static void main(String[] args) {
int in1[] = {1,2,3,4,5,6};
int in2[] = new int[in1.length];
int i,j=0;
for(i=in1.length-1;i>=0;i--){
in2[j] = in1[i];
j++;
}
for(int k=0;k<in2.length;k++){
System.out.println(in2[k]);
}
}
}
//3.无重复元素整数数组与一个整数,如果在数组中, 则输出下标;如果不存在,则输出-1。
public class IndexTest {
public static void main(String[] args) {
int n=100,j = -1;
int in[] = {12,24,100,8,28};
for(int i=0;i<in.length;i++){
if(n == in[i]){
j = i;
break;
}
}
System.out.println(j);
}
}
//4.输出数组元素的最小与最大值
public class MArray {
public static void main(String[] args) {
double d[] = {12.0,23.01,10.0,24.0};
double min = d[0],max = d[0];
for(int i=0;i<d.length;i++){
if(min > d[i]){
min = d[i];
}
if(max < d[i]){
max = d[i];
}
}
System.out.println(min);
System.out.println(max);
}
}
public class TestArray {
public static void main(String[] args) {
double[] myList = {1.9, 2.9, 3.4, 3.5};
// 打印所有数组元素
for (int i = 0; i < myList.length; i++) {
System.out.println(myList[i] + " ");
}
// 计算所有元素的总和
double total = 0;
for (int i = 0; i < myList.length; i++) {
total += myList[i];
}
System.out.println("Total is " + total);
// 查找最大元素
double max = myList[0];
for (int i = 1; i < myList.length; i++) {
if (myList[i] > max) max = myList[i];
}
System.out.println("Max is " + max);
}
}
For-Each 循环
for(type element: array)
{
System.out.println(element);
}
public class TestArray {
public static void main(String[] args) {
double[] myList = {1.9, 2.9, 3.4, 3.5};
// 打印所有数组元素
for (double element: myList) {
System.out.println(element);
}
}
}
package com.ahabest.array;
public class DyadicArray{
public static void main(String args[]){
//方法一:创建二维数组
int in[][] = {{1,2,3},{4,5},{6,7,8,9}};
//方法二:创建二维数组
String st[][] = new String[3][4];
st[0][0] = "但是";
st[0][1] = "rewwr";
st[0][2] = "dadada";
st[0][3] = "26";
st[1][0] = "发vs地方";
st[1][1] = "rewwr";
st[1][2] = "dadada";
st[1][3] = "28";
st[2][0] = "韩国";
st[2][1] = "rewwr";
st[2][2] = "dadada";
st[2][3] = "98";
//循环遍历数组
for(int i=0;i<in.length;i++){
for(int j=0;j<in[i].length;j++){
System.out.print(in[i][j]+" ");
}
}
System.out.print("\n");
for(int m=0;m<st.length;m++){
for(int n=0;n<st[m].length;n++){
System.out.print(st[m][n]+" ");
}
}
}
}
java.util.Arrays 类能方便地操作数组,它提供的所有方法都是静态的。
具有以下功能:
序号 |
方法和说明 |
1 |
public static int binarySearch(Object[] a, Object key) |
2 |
public static boolean equals(long[] a, long[] a2) |
3 |
public static void fill(int[] a, int val) |
4 |
public static void sort(Object[] a) |
标签:lis break 说明 list 否则 存在 输出 linear package
原文地址:https://www.cnblogs.com/Aha-Best/p/10884502.html