- Java三大特性: 封装、继承、多态;
- 定义三个参数, a,b; 交换 a,b的值
例如:
输入: 1 5
输出:a = 5 ; b = 1
public class Demo1 {public static void main(String[] args) {int a, b, temp;Scanner input = new Scanner(System.in);a = input.nextInt();b = input.nextInt();temp = a;a = b;b = temp;System.out.println("a = " + a + ";b = " + b);}}
控制台输出
1 5
a = 5;b = 1
- 定义 一个数组; 输入10个数(x>=0&&x<=100);将这10个数分为3个等级;
例如 :
输入: 59 60 70 80 88 45 90 100 95 96输出: A: 4 B: 4 C:2
package Weekly_Task;import java.util.Scanner;/*** @author Devil* @create 2021-10-24-20:27*/public class Demo2 {public static void main(String[] args) {Scanner input = new Scanner(System.in);int countA = 0, countB = 0, countC = 0;int[] array = new int[10];for (int i = 0; i < array.length; i++) {array[i] = input.nextInt();if(array[i]<=100&&array[i]>=90){countA++;}else if(array[i]>=60&&array[i]<90){countB++;}else {countC++;}}System.out.println("A:"+countA+" B:"+countB+" C:"+countC);}}
控制台输出
59 60 70 80 88 45 90 100 95 96
A:4 B:4 C:2
- 求1-100 的和
package Weekly_Task;/*** @author Devil* @create 2021-10-24-20:35*/public class Demo3 {public static void main(String[] args) {int sum = 0;for (int i = 0; i < 100; i++) {sum++;}System.out.println(sum);}}
控制台输出
100
- 定义一个数组,输入 5 个数,输出大于50的数
例如:
输入: 40 50 45 62 50输出: 62
package Weekly_Task;import java.util.Scanner;/*** @author Devil* @create 2021-10-24-20:39*/public class Demo4 {public static void main(String[] args) {Scanner input = new Scanner(System.in);int[] array = new int[4];for (int i = 0; i < 4; i++) {array[i] = input.nextInt();if(array[i]>50){System.out.print(array[i]);}}}}
控制台输出
40 50 45 62 50
62
