package com.kuang;
public class test1 {
public static void main(String[] args) {
// 100内奇偶数
int oddSum = 0;
int evenSum = 0;
for (int i = 0; i <= 100; i++) {
if (i % 2 != 0) {
oddSum += i;
} else {
evenSum += i;
}
}
System.out.println("奇数:" + oddSum);
System.out.println("偶数:" + evenSum);
// 1000内被5整除,每行三个
for (int i = 0; i <= 1000; i++) {
if(i%5==0){
System.out.print(i+"\t");
}
if(i%(5*3)==0){
System.out.println();
}
}
System.out.println();
// 九九乘法表
for (int i = 0; i < 10; i++) {
for (int a=1;a<=i;a++){
System.out.print(i +"*" + a +"="+ i*a+" ");
}
System.out.println();
}
}
}
package com.kuang;
public class zhishu {
public static void main(String[] args) {
int count = 0;
for (int i = 101; i < 150; i++) {
boolean flag;
flag = false;
for (int j = 2; j < i / 2; j++) {
if (i % j == 0) {
flag = true;
break;
}
}
// System.out.println(flag);
if(flag==false) {
System.out.println(i);
}
}
}
}
package com.kuang.method;
public class Digui {
public static void main(String[] args) {
System.out.println(f(5));
}
public static int f(int n) {
if (n == 1) {
return 1;
} else {
return n * f(n - 1);
}
}
}
package com.kuang.array;
public class static_array {
public static void main(String[] args) {
int[] b = {1,2,3,4};
for (int array : b) {
System.out.println(array);
}
}
}
package com.kuang.array;
public class static_array {
public static void main(String[] args) {
int[] b = {1,2,3,4};
for (int array : b) {
System.out.println(array);
}
PrintArray(b);
PrintArray(reverse(b));
}
public static void PrintArray(int[] array){
for (int i=0;i< array.length;i++) {
System.out.println(array[i] + "=" + array[i]);
}
}
public static int[] reverse(int[] array){
int[] result = new int[array.length];
// 反转
for (int i=0;i<array.length; i++) {
result[array.length-1-i] = array[i];
}
return result;
}
}
System.out.println(Arrays.toString(array));
package com.kuang.array;
import java.lang.reflect.Array;
import java.util.Arrays;
public class maopao {
public static void main(String[] args) {
int[] arrays = {1,9,5,8,3};
maopao_sort(arrays);
}
public static void maopao_sort(int[] arrays) {
int temp = 0;
for (int i = 0; i < arrays.length; i++) {
for (int j = i + 1; j < arrays.length; j++) {
if (arrays[i] > arrays[j]) {
temp = arrays[i];
arrays[i] = arrays[j];
arrays[j] = temp;
}
}
}
System.out.println(Arrays.toString(arrays));
}
}
public class Demo01 {
public static void main(String[] args) {
System.out.println(max(5,6));
}
public void print(){
System.out.println("6666");
// return;
}
public static int max(int a,int b){
return a>b ? a : b;
}
package com.kuang.face_class;
public class Demo02 {
public static void main(String[] args) {
Demo01 demo01 = new Demo01();
demo01.print();
int add = new Demo02().add(2,3);
System.out.println(add);
}
public int add(int a, int b){
return a+b;
}
}
Java中的构造器,一般来说是进行初始化。在运行时刻,可以通过调用方法或执行某些动作来确定初始值