0
点赞
收藏
分享

微信扫一扫

(一)蓝桥杯java基础知识必备

蓝桥杯java基础知识

文章目录


前言

提示:以下是本篇文章正文内容,下面案例可供参考

一、数组的复制

(1)clone();

将a数组的值赋值给c;


 int[] a = {1,2,34};
 int[] c = a.clone();

(2)System.arraycopy();

System.arraycopy(Object a, int begin_a, Object b, int begin_b, int length)从a复制到b,复制从a数组指定的位置begin_a开始,到begin_a+length-1结束。放置从b的begin_b开始,到begin_b+length-1结束。

int[] a = {1,2,34};
int[] b = new int[10];
System.arraycopy(a, 0, b, 0, 2);

(3)Arrays.copyOf();

Arrays.copyOf(int[] a, int length);//从a数组的第一个元素开始复制,复制length个元素。

int[] a = {1,3,5};
		int[] b = Arrays.copyOf(a, a.length-1);
		for(int i= 0;i<3;i++) {
			System.out.println(b[i]);
		}

(4)Arrays.copyOfRange();

Arrays.copyOfRange(int[] a,int from,int to);从from复制到to-1结束

		int[] a = {1,3,5};
		int[] b = Arrays.copyOfRange(a, 0, a.length);
		for(int i= 0;i<3;i++) {
			System.out.println(b[i]);
		}

二、常用输入输出

1.输入(要详细区分两者,空格容易失分)

in.next() 从缓冲区接收字符遇到空格后停止。 相当于 cin 和 scanf

in.nextLine() 从缓冲区接收字符,并且接收空格,遇到换行才停止,并且会自动舍弃换行。 相当于 gets()

代码如下(示例):

package 基础;
import java.util.*;
public class inputDemo {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String next = sc.next();
		String nextLine = sc.nextLine();
		System.out.println(next);
		System.out.println(nextLine);
	}
}

运行结果
在这里插入图片描述

2.输出

输出没有多大要求,一般蓝桥杯比赛中都是要求你进行数据返回的,输出主要是用于对代码的调试

总结

提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了java
基础知识

举报

相关推荐

0 条评论