java简单练习题(主要动手敲敲打发下被难题折磨后的时间,顺便补一下基础:D

数组查找

import java.util.Scanner;

/**
 * 
 * @author Akina好ぎだ:D UJNsk
 *
 */
public class chazhao {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int[] arr = new int[] { 20, 62, 04, 269, 423, 02, 666, 6 };
		Scanner inScanner = new Scanner(System.in);
		int a = inScanner.nextInt();
//		for (int i = 0; i < arr.length; i++) {         无调用方法时
//			if (arr[i] == a) {
//				System.out.println(i);
//
//			} else {
//				System.out.println("-1");
//				break;
//			}
//		}
		int index = chazhao(a, arr);
		System.out.println(index);
	}

	public static int chazhao(int a, int[] arr) {
		int index = -1;
		for (int i = 0; i < arr.length; i++) {
			if (arr[i] == a) {
				index = i;
			}
		}

		return index;

	}
}

逢七过

import java.util.Scanner;

public class feng7 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner inScanner = new Scanner(System.in);
//		for (int i = 0; i < 100; i++) {
//			if (i % 10 == 7 || i % 7 == 0 || i / 10 % 10 == 7) {
//				System.out.println(i);
//			}
//		}
		while (inScanner.hasNextInt()) {
			int a = inScanner.nextInt();

			if (a % 10 == 7 || a % 7 == 0 || a / 10 % 10 == 7) {
				System.out.print("true");

			} else {
				System.out.println("false");
			}
		}
	}

}

数组求和

public class shuzuqiuhe {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int[] a = new int[] { 68, 27, 95, 88, 11, 996, 51, 210 };
		int[] b = new int[] { 68, 27, 95, 88, 11, 996, 51, 210 };
		boolean flag = compare(a, b);
		System.out.println(flag);
	}

	public static boolean compare(int[] a, int[] b) {
		if (a.length != b.length) {
			return false;

		} else {
			for (int i = 0; i < a.length; i++) {
				if (a[i] != b[i]) {
					return false;
				}
			}
		}
		return true;
	}
}

switch

import java.util.Scanner;

public class Jianfei {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner inScanner = new Scanner(System.in);
		String aString = inScanner.next();
		switch (aString) {
		case "星期一": {

			System.out.println("吃饭");
			break;
		}
		case "星期二": {
			System.out.println("学习");
			break;
		}
		default:
			throw new IllegalArgumentException("Unexpected value: " + aString);
		}
	}

}

生兔兔✧(≖ ◡ ≖✿) 斐波那契数列

public class tuzi {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int[] arr = new int[20];
		arr[0] = 1;
		arr[1] = 1;
		System.out.println(arr[0]);
		System.out.println(arr[1]);
		for (int i = 2; i < arr.length; i++) {
			arr[i] = arr[i - 1] + arr[i - 2];

			System.out.println(arr[i]);
		}
	}

}

买鸡

小学数学题


public class maiji {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		/**
		 * 公鸡五元一只母鸡三元一只小鸡一元三只 一共有一百元 一共买一百只 优化:x<20 y<33 z=100-x-y粗略优化
		 * 
		 */
		for (int x = 0; x < 20; x++) {
			for (int y = 0; y < 33; y++) {
				int z = 100 - x - y;
				if (z % 3 == 0 && 5 * x + 3 * y + z / 3 == 100) {
					System.out.println(x + " " + y + " " + z);
				}
			}
		}
	}

}

仅用于记录,没有那么严谨惹,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值