数组查找
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);
}
}
}
}
}
仅用于记录,没有那么严谨惹,