【蓝桥杯】【算法训练】【Java100分】加法运算

加法运算_没用指针_100分

package 题解;

import java.util.Scanner;

public class _006_加法运算_没用指针_100分 {
	public static void main(String[] args) {
		GetTwoInts();
	}
	
	static void GetTwoInts(){
		Scanner scanner = new Scanner(System.in);
		int x = scanner.nextInt();
		int y = scanner.nextInt();
		System.out.println(x+y);
	}
}

加法运算_指针

package 题解;

import java.util.Scanner;

public class _006_加法运算_指针 {
	public static void main(String[] args) {
		int[] arr = new int[2];
		arr = GetTwoInts();
		int sum = 0;
		for (int i = 0; i < arr.length; i++) {
			sum+=arr[i];
		}
		System.out.println(sum);
	}
//返回了一个数组!!!!!也就是地址。。。指针。
	static int[] GetTwoInts(){
		int[] arr = new int[2];
		Scanner scanner = new Scanner(System.in);
		for (int i = 0; i < arr.length; i++) {
			arr[i] = scanner.nextInt();
		}
		return arr;
	}
}

发布了99 篇原创文章 · 获赞 18 · 访问量 3710

猜你喜欢

转载自blog.csdn.net/alovelypeach/article/details/104977800