mirror of
https://github.com/Dichgrem/Java.git
synced 2025-12-17 21:01:59 -05:00
Compare commits
1 Commits
main
...
b03fcbeded
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b03fcbeded |
95
.gitignore
vendored
95
.gitignore
vendored
@@ -1,95 +0,0 @@
|
|||||||
### Compiled class files
|
|
||||||
*.class
|
|
||||||
|
|
||||||
### Log files
|
|
||||||
*.log
|
|
||||||
|
|
||||||
### BlueJ files
|
|
||||||
*.ctxt
|
|
||||||
|
|
||||||
### Mobile Tools for Java (J2ME)
|
|
||||||
.mtj.tmp/
|
|
||||||
|
|
||||||
### Package Files
|
|
||||||
*.jar
|
|
||||||
*.war
|
|
||||||
*.nar
|
|
||||||
*.ear
|
|
||||||
*.zip
|
|
||||||
*.tar.gz
|
|
||||||
*.rar
|
|
||||||
|
|
||||||
### VM crash logs
|
|
||||||
hs_err_pid*
|
|
||||||
replay_pid*
|
|
||||||
|
|
||||||
# ========================
|
|
||||||
# Maven
|
|
||||||
# ========================
|
|
||||||
target/
|
|
||||||
pom.xml.tag
|
|
||||||
pom.xml.releaseBackup
|
|
||||||
pom.xml.versionsBackup
|
|
||||||
pom.xml.next
|
|
||||||
release.properties
|
|
||||||
dependency-reduced-pom.xml
|
|
||||||
buildNumber.properties
|
|
||||||
.mvn/timing.properties
|
|
||||||
.mvn/wrapper/maven-wrapper.jar
|
|
||||||
|
|
||||||
# ========================
|
|
||||||
# Gradle
|
|
||||||
# ========================
|
|
||||||
.gradle/
|
|
||||||
build/
|
|
||||||
!gradle-wrapper.jar
|
|
||||||
!*/src/main/**/build/
|
|
||||||
!*/src/test/**/build/
|
|
||||||
|
|
||||||
### Avoid ignoring Gradle wrapper
|
|
||||||
gradle-app.setting
|
|
||||||
|
|
||||||
# ========================
|
|
||||||
# IntelliJ IDEA
|
|
||||||
# ========================
|
|
||||||
.idea/
|
|
||||||
*.iml
|
|
||||||
*.ipr
|
|
||||||
*.iws
|
|
||||||
out/
|
|
||||||
|
|
||||||
# ========================
|
|
||||||
# Eclipse
|
|
||||||
# ========================
|
|
||||||
.project
|
|
||||||
.classpath
|
|
||||||
.cproject
|
|
||||||
.settings/
|
|
||||||
bin/
|
|
||||||
tmp/
|
|
||||||
|
|
||||||
# ========================
|
|
||||||
# NetBeans
|
|
||||||
# ========================
|
|
||||||
nbproject/private/
|
|
||||||
nbbuild/
|
|
||||||
dist/
|
|
||||||
nbdist/
|
|
||||||
.nb-gradle/
|
|
||||||
|
|
||||||
# ========================
|
|
||||||
# VS Code
|
|
||||||
# ========================
|
|
||||||
.vscode/
|
|
||||||
|
|
||||||
# ========================
|
|
||||||
# OS files
|
|
||||||
# ========================
|
|
||||||
# macOS
|
|
||||||
.DS_Store
|
|
||||||
|
|
||||||
# Windows
|
|
||||||
Thumbs.db
|
|
||||||
|
|
||||||
#local
|
|
||||||
com/study/test/
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.study.demo;
|
package com.study.demo;
|
||||||
|
|
||||||
public class Demo {
|
public class Demo {
|
||||||
public static void main(String[] args) {
|
public static void main(String [] args) {
|
||||||
System.out.println("HelloWorld!");
|
System.out.println("HelloWorld!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
package com.study.demo;
|
package com.study.demo;
|
||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
// I am 212306206
|
// I am 212306206
|
||||||
public class test1_type {
|
public class test1_type {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner (System.in);
|
||||||
int a = scanner.nextInt();
|
int a = scanner.nextInt();
|
||||||
int b = scanner.nextInt();
|
int b = scanner.nextInt();
|
||||||
int sum = a + b;
|
int sum = a + b;
|
||||||
System.out.println(a + " + " + b + " = " + sum);
|
System.out.println(a + " + " + b + " = " + sum);
|
||||||
scanner.close();
|
scanner.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
package com.study.demo;
|
package com.study.demo;
|
||||||
|
|
||||||
public class test2_for {
|
public class test2_for {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
int[] numbers = new int[5];
|
int[] numbers = new int[5];
|
||||||
for (int i = 0; i < numbers.length; i++) {
|
for (int i = 0; i < numbers.length; i++) {
|
||||||
numbers[i] = i * 10;
|
numbers[i] = i * 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.print("数组内容: ");
|
System.out.print("数组内容: ");
|
||||||
for (int i = 0; i < numbers.length; i++) {
|
for (int i = 0; i < numbers.length; i++) {
|
||||||
System.out.print(numbers[i] + " ");
|
System.out.print(numbers[i] + " ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
package com.study.demo;
|
package com.study.demo;
|
||||||
|
|
||||||
public class test3_1_99 {
|
public class test3_1_99 {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
int[] numbers = new int[99];
|
int[] numbers = new int[99];
|
||||||
|
|
||||||
for (int i = 0; i < numbers.length; i++) {
|
for (int i = 0; i < numbers.length; i++) {
|
||||||
numbers[i] = i + 1;
|
numbers[i] = i + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int sum = 0;
|
||||||
|
for (int i = 0; i < numbers.length; i++) {
|
||||||
|
sum += numbers[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("1+2+...+99 的和 = " + sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
int sum = 0;
|
|
||||||
for (int i = 0; i < numbers.length; i++) {
|
|
||||||
sum += numbers[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("1+2+...+99 的和 = " + sum);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
package com.study.demo;
|
package com.study.demo;
|
||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class test5 {
|
public class test5 {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
int a = scanner.nextInt();
|
int a = scanner.nextInt();
|
||||||
int b = scanner.nextInt();
|
int b = scanner.nextInt();
|
||||||
int c = scanner.nextInt();
|
int c = scanner.nextInt();
|
||||||
double pi = 3.1415926535;
|
double pi = 3.1415926535;
|
||||||
double area = a * b * c + a * c + (pi * c * c) / 4;
|
double area = a * b * c + a * c + (pi * c * c) / 4;
|
||||||
System.out.printf("%.3f\n", area / 10000);
|
System.out.printf("%.3f\n", area / 10000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,10 +3,10 @@ package com.study.demo;
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class test6 {
|
public class test6 {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
int n = scanner.nextInt();
|
int n = scanner.nextInt();
|
||||||
int result = 1 << n;
|
int result = 1 << n;
|
||||||
System.out.println(result);
|
System.out.println(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,12 +3,12 @@ package com.study.demo;
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class test7 {
|
public class test7 {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
int x = scanner.nextInt();
|
int x = scanner.nextInt();
|
||||||
int y = scanner.nextInt();
|
int y = scanner.nextInt();
|
||||||
int startYear = 2016, startMonth = 8;
|
int startYear = 2016, startMonth = 8;
|
||||||
int totalMonths = (x - startYear) * 12 + y - startMonth + 1;
|
int totalMonths = (x - startYear) * 12 + y - startMonth + 1;
|
||||||
System.out.println(totalMonths);
|
System.out.println(totalMonths);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,17 +3,17 @@ package com.study.demo;
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class test8 {
|
public class test8 {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
int x = scanner.nextInt();
|
int x = scanner.nextInt();
|
||||||
int k = scanner.nextInt();
|
int k = scanner.nextInt();
|
||||||
int a = x / 1000 % k;
|
int a = x / 1000 % k;
|
||||||
int b = x / 100 % 10 % k;
|
int b = x / 100 % 10 % k;
|
||||||
int c = x / 10 % 10 % k;
|
int c = x / 10 % 10 % k;
|
||||||
int d = x % 10 % k;
|
int d = x % 10 % k;
|
||||||
System.out.print(a);
|
System.out.print(a);
|
||||||
System.out.print(b);
|
System.out.print(b);
|
||||||
System.out.print(c);
|
System.out.print(c);
|
||||||
System.out.println(d);
|
System.out.println(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
com/study/demo/test3_1.class
Normal file
BIN
com/study/demo/test3_1.class
Normal file
Binary file not shown.
@@ -3,20 +3,20 @@ package com.study.demo;
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class test3_1 {
|
public class test3_1 {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
int n = scanner.nextInt();
|
int n = scanner.nextInt();
|
||||||
int[] arr = new int[n];
|
int[] arr = new int[n];
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
arr[i] = scanner.nextInt();
|
arr[i] = scanner.nextInt();
|
||||||
|
}
|
||||||
|
for (int i = 0; i < n / 2; i++) {
|
||||||
|
int temp = arr[i];
|
||||||
|
arr[i] = arr[n - 1 - i];
|
||||||
|
arr[n - 1 - i] = temp;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
System.out.print(arr[i] + (i == n - 1 ? "" : " "));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < n / 2; i++) {
|
|
||||||
int temp = arr[i];
|
|
||||||
arr[i] = arr[n - 1 - i];
|
|
||||||
arr[n - 1 - i] = temp;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
System.out.print(arr[i] + (i == n - 1 ? "" : " "));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
com/study/demo/test3_2.class
Normal file
BIN
com/study/demo/test3_2.class
Normal file
Binary file not shown.
@@ -3,21 +3,21 @@ package com.study.demo;
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class test3_2 {
|
public class test3_2 {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
int n = scanner.nextInt();
|
int n = scanner.nextInt();
|
||||||
int[] a = new int[n];
|
int[] a = new int[n];
|
||||||
int[] b = new int[n];
|
int[] b = new int[n];
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
a[i] = scanner.nextInt();
|
a[i] = scanner.nextInt();
|
||||||
|
}
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
b[i] = scanner.nextInt();
|
||||||
|
}
|
||||||
|
int sum = 0;
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
sum += a[i] * b[i];
|
||||||
|
}
|
||||||
|
System.out.println(sum);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
b[i] = scanner.nextInt();
|
|
||||||
}
|
|
||||||
int sum = 0;
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
sum += a[i] * b[i];
|
|
||||||
}
|
|
||||||
System.out.println(sum);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
com/study/demo/test3_3.class
Normal file
BIN
com/study/demo/test3_3.class
Normal file
Binary file not shown.
@@ -3,23 +3,23 @@ package com.study.demo;
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class test3_3 {
|
public class test3_3 {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
int n = scanner.nextInt();
|
int n = scanner.nextInt();
|
||||||
int[] arr = new int[n];
|
int[] arr = new int[n];
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
arr[i] = scanner.nextInt();
|
arr[i] = scanner.nextInt();
|
||||||
}
|
}
|
||||||
int maxLen = 1, currentLen = 1;
|
int maxLen = 1, currentLen = 1;
|
||||||
for (int i = 1; i < n; i++) {
|
for (int i = 1; i < n; i++) {
|
||||||
if (arr[i] == arr[i - 1]) {
|
if (arr[i] == arr[i - 1]) {
|
||||||
currentLen++;
|
currentLen++;
|
||||||
} else {
|
} else {
|
||||||
|
maxLen = Math.max(maxLen, currentLen);
|
||||||
|
currentLen = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
maxLen = Math.max(maxLen, currentLen);
|
maxLen = Math.max(maxLen, currentLen);
|
||||||
currentLen = 1;
|
System.out.println(maxLen);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
maxLen = Math.max(maxLen, currentLen);
|
|
||||||
System.out.println(maxLen);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
com/study/demo/test3_4.class
Normal file
BIN
com/study/demo/test3_4.class
Normal file
Binary file not shown.
@@ -3,21 +3,21 @@ package com.study.demo;
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class test3_4 {
|
public class test3_4 {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
int n = scanner.nextInt();
|
int n = scanner.nextInt();
|
||||||
int m = scanner.nextInt();
|
int m = scanner.nextInt();
|
||||||
int[][] image = new int[n][m];
|
int[][] image = new int[n][m];
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
for (int j = 0; j < m; j++) {
|
for (int j = 0; j < m; j++) {
|
||||||
image[i][j] = scanner.nextInt();
|
image[i][j] = scanner.nextInt();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
for (int j = 0; j < m; j++) {
|
||||||
|
for (int i = n - 1; i >= 0; i--) {
|
||||||
|
System.out.print(image[i][j] + (i == 0 ? "" : " "));
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (int j = 0; j < m; j++) {
|
|
||||||
for (int i = n - 1; i >= 0; i--) {
|
|
||||||
System.out.print(image[i][j] + (i == 0 ? "" : " "));
|
|
||||||
}
|
|
||||||
System.out.println();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
com/study/demo/test3_5.class
Normal file
BIN
com/study/demo/test3_5.class
Normal file
Binary file not shown.
@@ -3,32 +3,32 @@ package com.study.demo;
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class test3_5 {
|
public class test3_5 {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
int n = scanner.nextInt();
|
int n = scanner.nextInt();
|
||||||
int[] t = new int[n - 1];
|
int[] t = new int[n - 1];
|
||||||
int[] s = new int[n];
|
int[] s = new int[n];
|
||||||
for (int i = 0; i < n - 1; i++) {
|
for (int i = 0; i < n - 1; i++) {
|
||||||
t[i] = scanner.nextInt();
|
t[i] = scanner.nextInt();
|
||||||
}
|
}
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
s[i] = scanner.nextInt();
|
s[i] = scanner.nextInt();
|
||||||
}
|
}
|
||||||
int x = scanner.nextInt();
|
int x = scanner.nextInt();
|
||||||
int y = scanner.nextInt();
|
int y = scanner.nextInt();
|
||||||
|
|
||||||
int total = 0;
|
int total = 0;
|
||||||
if (x < y) {
|
if (x < y) {
|
||||||
for (int i = x - 1; i < y - 1; i++) {
|
for (int i = x - 1; i < y - 1; i++) {
|
||||||
total += s[i] + t[i];
|
total += s[i] + t[i];
|
||||||
}
|
}
|
||||||
total += s[y - 1];
|
total += s[y - 1];
|
||||||
} else {
|
} else {
|
||||||
for (int i = x - 1; i >= y; i--) {
|
for (int i = x - 1; i >= y; i--) {
|
||||||
total += s[i] + (i > 0 ? t[i - 1] : 0);
|
total += s[i] + (i > 0 ? t[i - 1] : 0);
|
||||||
}
|
}
|
||||||
total += s[y - 1];
|
total += s[y - 1];
|
||||||
|
}
|
||||||
|
System.out.println(total);
|
||||||
}
|
}
|
||||||
System.out.println(total);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,36 +1,36 @@
|
|||||||
package com.study.demo2;
|
package com.study.demo2;
|
||||||
|
|
||||||
public class Account {
|
public class Account {
|
||||||
private String accountId;
|
private String accountId;
|
||||||
private String owner;
|
private String owner;
|
||||||
private double balance;
|
private double balance;
|
||||||
|
|
||||||
public Account(String accountId, String owner, double balance) {
|
public Account(String accountId, String owner, double balance) {
|
||||||
this.accountId = accountId;
|
this.accountId = accountId;
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.balance = balance;
|
this.balance = balance;
|
||||||
}
|
|
||||||
|
|
||||||
public void deposit(double amount) {
|
|
||||||
if (amount > 0) {
|
|
||||||
balance += amount;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void withdraw(double amount) {
|
public void deposit(double amount) {
|
||||||
if (amount > 0 && amount <= balance) {
|
if (amount > 0) {
|
||||||
balance -= amount;
|
balance += amount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void transfer(Account target, double amount) {
|
public void withdraw(double amount) {
|
||||||
if (amount > 0 && amount <= balance) {
|
if (amount > 0 && amount <= balance) {
|
||||||
this.balance -= amount;
|
balance -= amount;
|
||||||
target.balance += amount;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public double getBalance() {
|
public void transfer(Account target, double amount) {
|
||||||
return balance;
|
if (amount > 0 && amount <= balance) {
|
||||||
}
|
this.balance -= amount;
|
||||||
}
|
target.balance += amount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getBalance() {
|
||||||
|
return balance;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
package com.study.demo2;
|
package com.study.demo2;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Account acc1 = new Account("A001", "张三", 1000);
|
Account acc1 = new Account("A001", "张三", 1000);
|
||||||
Account acc2 = new Account("A002", "李四", 500);
|
Account acc2 = new Account("A002", "李四", 500);
|
||||||
|
|
||||||
acc1.deposit(200);
|
acc1.deposit(200);
|
||||||
acc1.withdraw(100);
|
acc1.withdraw(100);
|
||||||
acc1.transfer(acc2, 300);
|
acc1.transfer(acc2, 300);
|
||||||
|
|
||||||
System.out.println("账户1余额:" + acc1.getBalance());
|
System.out.println("账户1余额:" + acc1.getBalance());
|
||||||
System.out.println("账户2余额:" + acc2.getBalance());
|
System.out.println("账户2余额:" + acc2.getBalance());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,45 +1,44 @@
|
|||||||
package com.study.demo2;
|
package com.study.demo2;
|
||||||
|
|
||||||
public abstract class Animal {
|
public abstract class Animal {
|
||||||
protected String name;
|
protected String name;
|
||||||
|
|
||||||
public Animal(String name) {
|
public Animal(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void makeSound();
|
public abstract void makeSound();
|
||||||
|
public abstract void move();
|
||||||
public abstract void move();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Dog extends Animal {
|
class Dog extends Animal {
|
||||||
public Dog(String name) {
|
public Dog(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void makeSound() {
|
public void makeSound() {
|
||||||
System.out.println(name + " 汪汪叫");
|
System.out.println(name + " 汪汪叫");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void move() {
|
public void move() {
|
||||||
System.out.println(name + " 跑动");
|
System.out.println(name + " 跑动");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Bird extends Animal {
|
class Bird extends Animal {
|
||||||
public Bird(String name) {
|
public Bird(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void makeSound() {
|
public void makeSound() {
|
||||||
System.out.println(name + " 叽叽喳喳");
|
System.out.println(name + " 叽叽喳喳");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void move() {
|
public void move() {
|
||||||
System.out.println(name + " 飞翔");
|
System.out.println(name + " 飞翔");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
package com.study.demo2;
|
package com.study.demo2;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Animal dog = new Dog("Buddy");
|
Animal dog = new Dog("Buddy");
|
||||||
Animal bird = new Bird("Tweety");
|
Animal bird = new Bird("Tweety");
|
||||||
dog.makeSound();
|
dog.makeSound();
|
||||||
dog.move();
|
dog.move();
|
||||||
bird.makeSound();
|
bird.makeSound();
|
||||||
bird.move();
|
bird.move();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,38 +1,37 @@
|
|||||||
package com.study.demo2;
|
package com.study.demo2;
|
||||||
|
|
||||||
public class Rectangle {
|
public class Rectangle {
|
||||||
private double width = 1.0;
|
private double width = 1.0;
|
||||||
private double height = 1.0;
|
private double height = 1.0;
|
||||||
|
|
||||||
public Rectangle() {
|
public Rectangle() {}
|
||||||
}
|
|
||||||
|
|
||||||
public Rectangle(double width, double height) {
|
public Rectangle(double width, double height) {
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getArea() {
|
public double getArea() {
|
||||||
return width * height;
|
return width * height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getPerimeter() {
|
public double getPerimeter() {
|
||||||
return 2 * (width + height);
|
return 2 * (width + height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getWidth() {
|
public double getWidth() {
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWidth(double width) {
|
public void setWidth(double width) {
|
||||||
this.width = width;
|
this.width = width;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getHeight() {
|
public double getHeight() {
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHeight(double height) {
|
public void setHeight(double height) {
|
||||||
this.height = height;
|
this.height = height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
package com.study.demo2;
|
package com.study.demo2;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Rectangle rect1 = new Rectangle(5.0, 3.0);
|
Rectangle rect1 = new Rectangle(5.0, 3.0);
|
||||||
System.out.println("面积:" + rect1.getArea());
|
System.out.println("面积:" + rect1.getArea());
|
||||||
System.out.println("周长:" + rect1.getPerimeter());
|
System.out.println("周长:" + rect1.getPerimeter());
|
||||||
|
|
||||||
Rectangle rect2 = new Rectangle();
|
Rectangle rect2 = new Rectangle();
|
||||||
System.out.println("默认面积:" + rect2.getArea());
|
System.out.println("默认面积:" + rect2.getArea());
|
||||||
System.out.println("默认周长:" + rect2.getPerimeter());
|
System.out.println("默认周长:" + rect2.getPerimeter());
|
||||||
|
|
||||||
rect2.setWidth(2.5);
|
rect2.setWidth(2.5);
|
||||||
rect2.setHeight(4.0);
|
rect2.setHeight(4.0);
|
||||||
System.out.println("修改后面积:" + rect2.getArea());
|
System.out.println("修改后面积:" + rect2.getArea());
|
||||||
System.out.println("修改后周长:" + rect2.getPerimeter());
|
System.out.println("修改后周长:" + rect2.getPerimeter());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,46 +1,40 @@
|
|||||||
package com.study.demo2;
|
package com.study.demo2;
|
||||||
|
|
||||||
public class Student {
|
public class Student {
|
||||||
private String id;
|
private String id;
|
||||||
private String name;
|
private String name;
|
||||||
private int[] score = new int[10];
|
private int[] score = new int[10];
|
||||||
|
|
||||||
public Student(String id, String name, int[] scores) {
|
public Student(String id, String name, int[] scores) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
if (scores.length == 10) {
|
if (scores.length == 10) {
|
||||||
this.score = scores;
|
this.score = scores;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public double getAverage() {
|
public double getAverage() {
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
for (int s : score) {
|
for (int s : score) {
|
||||||
sum += s;
|
sum += s;
|
||||||
|
}
|
||||||
|
return (double) Math.round((sum / 10.0) * 100) / 100;
|
||||||
}
|
}
|
||||||
return (double) Math.round((sum / 10.0) * 100) / 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMaxScore() {
|
public int getMaxScore() {
|
||||||
int max = score[0];
|
int max = score[0];
|
||||||
for (int s : score) {
|
for (int s : score) {
|
||||||
if (s > max)
|
if (s > max) max = s;
|
||||||
max = s;
|
}
|
||||||
|
return max;
|
||||||
}
|
}
|
||||||
return max;
|
|
||||||
}
|
|
||||||
|
|
||||||
public char getGrade() {
|
public char getGrade() {
|
||||||
double avg = getAverage();
|
double avg = getAverage();
|
||||||
if (avg >= 90)
|
if (avg >= 90) return 'A';
|
||||||
return 'A';
|
else if (avg >= 80) return 'B';
|
||||||
else if (avg >= 80)
|
else if (avg >= 70) return 'C';
|
||||||
return 'B';
|
else if (avg >= 60) return 'D';
|
||||||
else if (avg >= 70)
|
else return 'E';
|
||||||
return 'C';
|
}
|
||||||
else if (avg >= 60)
|
}
|
||||||
return 'D';
|
|
||||||
else
|
|
||||||
return 'E';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
package com.study.demo2;
|
package com.study.demo2;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
int[] scores = { 85, 90, 78, 92, 88, 76, 95, 89, 79, 94 };
|
int[] scores = {85, 90, 78, 92, 88, 76, 95, 89, 79, 94};
|
||||||
Student student = new Student("5001", "张三", scores);
|
Student student = new Student("5001", "张三", scores);
|
||||||
System.out.println("平均分: " + student.getAverage());
|
|
||||||
System.out.println("最高分: " + student.getMaxScore());
|
System.out.println("平均分: " + student.getAverage());
|
||||||
System.out.println("等级: " + student.getGrade());
|
System.out.println("最高分: " + student.getMaxScore());
|
||||||
}
|
System.out.println("等级: " + student.getGrade());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
BIN
com/study/demo3/Bicycle.class
Normal file
BIN
com/study/demo3/Bicycle.class
Normal file
Binary file not shown.
BIN
com/study/demo3/Book.class
Normal file
BIN
com/study/demo3/Book.class
Normal file
Binary file not shown.
BIN
com/study/demo3/Car.class
Normal file
BIN
com/study/demo3/Car.class
Normal file
Binary file not shown.
BIN
com/study/demo3/EBook.class
Normal file
BIN
com/study/demo3/EBook.class
Normal file
Binary file not shown.
BIN
com/study/demo3/Library.class
Normal file
BIN
com/study/demo3/Library.class
Normal file
Binary file not shown.
BIN
com/study/demo3/LibraryTest.class
Normal file
BIN
com/study/demo3/LibraryTest.class
Normal file
Binary file not shown.
BIN
com/study/demo3/Main2.class
Normal file
BIN
com/study/demo3/Main2.class
Normal file
Binary file not shown.
BIN
com/study/demo3/PrintedBook.class
Normal file
BIN
com/study/demo3/PrintedBook.class
Normal file
Binary file not shown.
BIN
com/study/demo3/StudentManager.class
Normal file
BIN
com/study/demo3/StudentManager.class
Normal file
Binary file not shown.
BIN
com/study/demo3/Train.class
Normal file
BIN
com/study/demo3/Train.class
Normal file
Binary file not shown.
BIN
com/study/demo3/Vehicle.class
Normal file
BIN
com/study/demo3/Vehicle.class
Normal file
Binary file not shown.
@@ -1,9 +0,0 @@
|
|||||||
package com.study.demo4;
|
|
||||||
|
|
||||||
class AlipayPayment implements PaymentProcessor {
|
|
||||||
@Override
|
|
||||||
public boolean pay(double amount) {
|
|
||||||
System.out.println("支付宝支付: " + amount);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
package com.study.demo4;
|
|
||||||
|
|
||||||
class BikeDeliveryCalculator implements DeliveryFeeCalculator {
|
|
||||||
@Override
|
|
||||||
public double calculateFee(double distance) {
|
|
||||||
if (distance <= 5) {
|
|
||||||
return 5.0; // 起步价
|
|
||||||
}
|
|
||||||
return 5.0 + (distance - 5) * 1.5;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package com.study.demo4;
|
|
||||||
|
|
||||||
class CarDeliveryCalculator implements DeliveryFeeCalculator {
|
|
||||||
@Override
|
|
||||||
public double calculateFee(double distance) {
|
|
||||||
if (distance <= 5) {
|
|
||||||
return 10.0; // 起步价
|
|
||||||
}
|
|
||||||
return 10.0 + (distance - 5) * 2.0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package com.study.demo4;
|
|
||||||
|
|
||||||
class CreditCardPayment implements PaymentProcessor {
|
|
||||||
@Override
|
|
||||||
public boolean pay(double amount) {
|
|
||||||
System.out.println("银行卡支付: " + amount);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package com.study.demo4;
|
|
||||||
|
|
||||||
interface DeliveryFeeCalculator {
|
|
||||||
double calculateFee(double distance);
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
package com.study.demo4;
|
|
||||||
|
|
||||||
abstract class HomeAppliance implements SmartDevice {
|
|
||||||
protected String name;
|
|
||||||
protected boolean isOn;
|
|
||||||
|
|
||||||
public HomeAppliance(String name) {
|
|
||||||
this.name = name;
|
|
||||||
this.isOn = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void turnOn() {
|
|
||||||
isOn = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void turnOff() {
|
|
||||||
isOn = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getStatus() {
|
|
||||||
return name + " is " + (isOn ? "ON" : "OFF");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package com.study.demo4;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
class HomeController {
|
|
||||||
private List<SmartDevice> devices = new ArrayList<>();
|
|
||||||
|
|
||||||
public void addDevice(SmartDevice device) {
|
|
||||||
devices.add(device);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDeviceStatus(String name) {
|
|
||||||
for (SmartDevice device : devices) {
|
|
||||||
if (device.getStatus().contains(name)) {
|
|
||||||
return device.getStatus();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "Device not found";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package com.study.demo4;
|
|
||||||
|
|
||||||
class PaymentFactory {
|
|
||||||
public static PaymentProcessor getProcessor(String type) {
|
|
||||||
switch (type.toLowerCase()) {
|
|
||||||
case "wechat":
|
|
||||||
return new WechatPayment();
|
|
||||||
case "alipay":
|
|
||||||
return new AlipayPayment();
|
|
||||||
case "card":
|
|
||||||
return new CreditCardPayment();
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException("不支持的支付方式");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
package com.study.demo4;
|
|
||||||
|
|
||||||
interface PaymentProcessor {
|
|
||||||
boolean pay(double amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package com.study.demo4;
|
|
||||||
|
|
||||||
class SmartAirConditioner extends HomeAppliance {
|
|
||||||
public SmartAirConditioner(String name) {
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package com.study.demo4;
|
|
||||||
|
|
||||||
interface SmartDevice {
|
|
||||||
void turnOn();
|
|
||||||
void turnOff();
|
|
||||||
String getStatus();
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package com.study.demo4;
|
|
||||||
|
|
||||||
class SmartLight extends HomeAppliance {
|
|
||||||
public SmartLight(String name) {
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package com.study.demo4;
|
|
||||||
|
|
||||||
class SmartMasher extends HomeAppliance {
|
|
||||||
public SmartMasher(String name) {
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
package com.study.demo4;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class TestControl {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
HomeController controller = new HomeController();
|
|
||||||
|
|
||||||
// 创建设备
|
|
||||||
SmartLight light = new SmartLight("Living Room Light");
|
|
||||||
SmartAirConditioner ac = new SmartAirConditioner("Bedroom AC");
|
|
||||||
SmartMasher masher = new SmartMasher("Kitchen Masher");
|
|
||||||
|
|
||||||
// 添加到控制器
|
|
||||||
controller.addDevice(light);
|
|
||||||
controller.addDevice(ac);
|
|
||||||
controller.addDevice(masher);
|
|
||||||
|
|
||||||
// 测试设备状态
|
|
||||||
light.turnOff();
|
|
||||||
ac.turnOff();
|
|
||||||
masher.turnOn();
|
|
||||||
|
|
||||||
// 查询状态
|
|
||||||
System.out.println(controller.getDeviceStatus("Living Room Light"));
|
|
||||||
System.out.println(controller.getDeviceStatus("Bedroom AC"));
|
|
||||||
System.out.println(controller.getDeviceStatus("Kitchen Masher"));
|
|
||||||
System.out.println(controller.getDeviceStatus("Non-existent Device"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package com.study.demo4;
|
|
||||||
|
|
||||||
public class TestPay {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
PaymentProcessor processor = PaymentFactory.getProcessor("alipay");
|
|
||||||
processor.pay(666.0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
package com.study.demo4;
|
|
||||||
|
|
||||||
public class TestTransport {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
// 测试自行车配送
|
|
||||||
DeliveryFeeCalculator bike = new BikeDeliveryCalculator();
|
|
||||||
System.out.println("自行车配送 3km: ¥" + bike.calculateFee(3));
|
|
||||||
System.out.println("自行车配送 8km: ¥" + bike.calculateFee(8));
|
|
||||||
|
|
||||||
// 测试汽车配送
|
|
||||||
DeliveryFeeCalculator car = new CarDeliveryCalculator();
|
|
||||||
System.out.println("汽车配送 3km: ¥" + car.calculateFee(3));
|
|
||||||
System.out.println("汽车配送 8km: ¥" + car.calculateFee(8));
|
|
||||||
|
|
||||||
// 对比不同距离的费用
|
|
||||||
System.out.println("\n费用对比:");
|
|
||||||
for (int km = 1; km <= 10; km++) {
|
|
||||||
System.out.printf("%dkm: 自行车¥%.1f, 汽车¥%.1f%n",
|
|
||||||
km, bike.calculateFee(km), car.calculateFee(km));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package com.study.demo4;
|
|
||||||
|
|
||||||
class WechatPayment implements PaymentProcessor {
|
|
||||||
@Override
|
|
||||||
public boolean pay(double amount) {
|
|
||||||
System.out.println("微信支付: " + amount);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
package com.study.demo5;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
|
|
||||||
public class DataIO {
|
|
||||||
public void writeConfig(String path) {
|
|
||||||
try (DataOutputStream dos = new DataOutputStream(
|
|
||||||
new FileOutputStream(path))) {
|
|
||||||
|
|
||||||
dos.writeUTF("李华"); // 用户名
|
|
||||||
dos.writeInt(25); // 年龄
|
|
||||||
dos.writeBoolean(true); // 是否启用
|
|
||||||
dos.writeDouble(1234.56); // 余额
|
|
||||||
|
|
||||||
System.out.println("配置写入成功: " + path);
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.err.println("写入配置失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readConfig(String path) {
|
|
||||||
try (DataInputStream dis = new DataInputStream(
|
|
||||||
new FileInputStream(path))) {
|
|
||||||
|
|
||||||
String username = dis.readUTF();
|
|
||||||
int age = dis.readInt();
|
|
||||||
boolean enabled = dis.readBoolean();
|
|
||||||
double balance = dis.readDouble();
|
|
||||||
|
|
||||||
System.out.println("用户名: " + username);
|
|
||||||
System.out.println("年龄: " + age);
|
|
||||||
System.out.println("是否启用: " + enabled);
|
|
||||||
System.out.println("余额: " + balance);
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.err.println("读取配置失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package com.study.demo5;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
|
|
||||||
public class FileCopy {
|
|
||||||
public void copy(String source, String target) {
|
|
||||||
try (FileInputStream fis = new FileInputStream(source);
|
|
||||||
FileOutputStream fos = new FileOutputStream(target)) {
|
|
||||||
byte[] buffer = new byte[1024];
|
|
||||||
int bytesRead;
|
|
||||||
while ((bytesRead = fis.read(buffer)) != -1) {
|
|
||||||
fos.write(buffer, 0, bytesRead);
|
|
||||||
}
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
System.err.println("源文件未找到: " + e.getMessage());
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.err.println("文件复制失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package com.study.demo5;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
|
|
||||||
public class FileStat {
|
|
||||||
public long countBytes(String filePath) {
|
|
||||||
long totalBytes = 0;
|
|
||||||
|
|
||||||
try (FileInputStream fis = new FileInputStream(filePath)) {
|
|
||||||
|
|
||||||
byte[] buffer = new byte[1024];
|
|
||||||
int bytesRead;
|
|
||||||
|
|
||||||
while ((bytesRead = fis.read(buffer)) != -1) {
|
|
||||||
totalBytes += bytesRead;
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.err.println("文件读取失败: " + e.getMessage());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return totalBytes;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package com.study.demo5;
|
|
||||||
|
|
||||||
public class Main {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
// 7.1 测试
|
|
||||||
FileCopy fc = new FileCopy();
|
|
||||||
fc.copy("source.txt", "target.txt");
|
|
||||||
// 7.2 测试
|
|
||||||
DataIO dataIO = new DataIO();
|
|
||||||
dataIO.writeConfig("config.bin");
|
|
||||||
dataIO.readConfig("config.bin");
|
|
||||||
// 7.3 测试
|
|
||||||
FileStat fs = new FileStat();
|
|
||||||
long size = fs.countBytes("test3.txt");
|
|
||||||
System.out.println("文件大小: " + size + " 字节");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
package com.study.demo6;
|
|
||||||
|
|
||||||
public class SumThread {
|
|
||||||
static class PartSumTask implements Runnable {
|
|
||||||
private final int[] array;
|
|
||||||
private final int start;
|
|
||||||
private final int end;
|
|
||||||
public long result;
|
|
||||||
|
|
||||||
public PartSumTask(int[] array, int start, int end) {
|
|
||||||
this.array = array;
|
|
||||||
this.start = start;
|
|
||||||
this.end = end;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
long sum = 0;
|
|
||||||
for (int i = start; i <= end; i++) {
|
|
||||||
sum += array[i];
|
|
||||||
}
|
|
||||||
result = sum;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) throws InterruptedException {
|
|
||||||
int size = 1_000_000;
|
|
||||||
int[] array = new int[size];
|
|
||||||
for (int i = 0; i < size; i++) {
|
|
||||||
array[i] = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
PartSumTask task1 = new PartSumTask(array, 0, 333_333);
|
|
||||||
PartSumTask task2 = new PartSumTask(array, 333_334, 666_666);
|
|
||||||
PartSumTask task3 = new PartSumTask(array, 666_667, 999_999);
|
|
||||||
|
|
||||||
Thread t1 = new Thread(task1);
|
|
||||||
Thread t2 = new Thread(task2);
|
|
||||||
Thread t3 = new Thread(task3);
|
|
||||||
|
|
||||||
t1.start();
|
|
||||||
t2.start();
|
|
||||||
t3.start();
|
|
||||||
|
|
||||||
t1.join();
|
|
||||||
t2.join();
|
|
||||||
t3.join();
|
|
||||||
|
|
||||||
long total = task1.result + task2.result + task3.result;
|
|
||||||
System.out.println("总和为:" + total);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package com.study.demo6;
|
|
||||||
|
|
||||||
public class ThreadDemo1 {
|
|
||||||
static class MyThread extends Thread {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
for (int i = 1; i <= 5; i++) {
|
|
||||||
System.out.println("当前线程:" + getName() + ",输出次数 " + i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
MyThread s1 = new MyThread();
|
|
||||||
MyThread s2 = new MyThread();
|
|
||||||
|
|
||||||
s1.start();
|
|
||||||
s2.start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
package com.study.demo6;
|
|
||||||
|
|
||||||
public class ThreadDemo2 {
|
|
||||||
static class CountTask implements Runnable {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
for (int i = 1; i <= 10; i++) {
|
|
||||||
System.out.println(Thread.currentThread().getName() + " 计数:" + i);
|
|
||||||
try {
|
|
||||||
Thread.sleep(500);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
Thread t = new Thread(new CountTask(), "计数线程");
|
|
||||||
t.start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||||
outputs = { self, nixpkgs }:
|
outputs = { self, nixpkgs }:
|
||||||
let
|
let
|
||||||
supportedSystems = [ "x86_64-linux" ];
|
supportedSystems = [ "x86_64-linux" "aarch64-linux" ];
|
||||||
forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f {
|
forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f {
|
||||||
pkgs = import nixpkgs { inherit self system; };
|
pkgs = import nixpkgs { inherit self system; };
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user