mirror of
https://github.com/Dichgrem/Java.git
synced 2025-12-16 12:41:58 -05:00
start:java8
This commit is contained in:
7
com/study/demo/Demo.java
Normal file
7
com/study/demo/Demo.java
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package com.study.demo;
|
||||||
|
|
||||||
|
public class Demo {
|
||||||
|
public static void main(String [] args) {
|
||||||
|
System.out.println("HelloWorld!");
|
||||||
|
}
|
||||||
|
}
|
||||||
13
com/study/demo/test1_1.java
Normal file
13
com/study/demo/test1_1.java
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package com.study.demo;
|
||||||
|
import java.util.Scanner;
|
||||||
|
// I am 212306206
|
||||||
|
public class test1_type {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner scanner = new Scanner (System.in);
|
||||||
|
int a = scanner.nextInt();
|
||||||
|
int b = scanner.nextInt();
|
||||||
|
int sum = a + b;
|
||||||
|
System.out.println(a + " + " + b + " = " + sum);
|
||||||
|
scanner.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
16
com/study/demo/test1_2.java
Normal file
16
com/study/demo/test1_2.java
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package com.study.demo;
|
||||||
|
|
||||||
|
public class test2_for {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int[] numbers = new int[5];
|
||||||
|
for (int i = 0; i < numbers.length; i++) {
|
||||||
|
numbers[i] = i * 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.print("数组内容: ");
|
||||||
|
for (int i = 0; i < numbers.length; i++) {
|
||||||
|
System.out.print(numbers[i] + " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
19
com/study/demo/test1_3.java
Normal file
19
com/study/demo/test1_3.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package com.study.demo;
|
||||||
|
|
||||||
|
public class test3_1_99 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int[] numbers = new int[99];
|
||||||
|
|
||||||
|
for (int i = 0; i < numbers.length; i++) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
14
com/study/demo/test2_1.java
Normal file
14
com/study/demo/test2_1.java
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package com.study.demo;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class test4 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
double r1 = sc.nextDouble();
|
||||||
|
double r2 = sc.nextDouble();
|
||||||
|
sc.close();
|
||||||
|
|
||||||
|
double R = 1 / (1 / r1 + 1 / r2);
|
||||||
|
System.out.printf("%.2f\n", R);
|
||||||
|
}
|
||||||
|
}
|
||||||
14
com/study/demo/test2_2.java
Normal file
14
com/study/demo/test2_2.java
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package com.study.demo;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class test5 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
int a = scanner.nextInt();
|
||||||
|
int b = scanner.nextInt();
|
||||||
|
int c = scanner.nextInt();
|
||||||
|
double pi = 3.1415926535;
|
||||||
|
double area = a * b * c + a * c + (pi * c * c) / 4;
|
||||||
|
System.out.printf("%.3f\n", area / 10000);
|
||||||
|
}
|
||||||
|
}
|
||||||
12
com/study/demo/test2_3.java
Normal file
12
com/study/demo/test2_3.java
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package com.study.demo;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class test6 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
int n = scanner.nextInt();
|
||||||
|
int result = 1 << n;
|
||||||
|
System.out.println(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
14
com/study/demo/test2_4.java
Normal file
14
com/study/demo/test2_4.java
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package com.study.demo;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class test7 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
int x = scanner.nextInt();
|
||||||
|
int y = scanner.nextInt();
|
||||||
|
int startYear = 2016, startMonth = 8;
|
||||||
|
int totalMonths = (x - startYear) * 12 + y - startMonth + 1;
|
||||||
|
System.out.println(totalMonths);
|
||||||
|
}
|
||||||
|
}
|
||||||
19
com/study/demo/test2_5.java
Normal file
19
com/study/demo/test2_5.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package com.study.demo;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class test8 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
int x = scanner.nextInt();
|
||||||
|
int k = scanner.nextInt();
|
||||||
|
int a = x / 1000 % k;
|
||||||
|
int b = x / 100 % 10 % k;
|
||||||
|
int c = x / 10 % 10 % k;
|
||||||
|
int d = x % 10 % k;
|
||||||
|
System.out.print(a);
|
||||||
|
System.out.print(b);
|
||||||
|
System.out.print(c);
|
||||||
|
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.
22
com/study/demo/test3_1.java
Normal file
22
com/study/demo/test3_1.java
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package com.study.demo;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class test3_1 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
int n = scanner.nextInt();
|
||||||
|
int[] arr = new int[n];
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
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 ? "" : " "));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
com/study/demo/test3_2.class
Normal file
BIN
com/study/demo/test3_2.class
Normal file
Binary file not shown.
23
com/study/demo/test3_2.java
Normal file
23
com/study/demo/test3_2.java
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package com.study.demo;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class test3_2 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
int n = scanner.nextInt();
|
||||||
|
int[] a = new int[n];
|
||||||
|
int[] b = new int[n];
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
com/study/demo/test3_3.class
Normal file
BIN
com/study/demo/test3_3.class
Normal file
Binary file not shown.
25
com/study/demo/test3_3.java
Normal file
25
com/study/demo/test3_3.java
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package com.study.demo;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class test3_3 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
int n = scanner.nextInt();
|
||||||
|
int[] arr = new int[n];
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
arr[i] = scanner.nextInt();
|
||||||
|
}
|
||||||
|
int maxLen = 1, currentLen = 1;
|
||||||
|
for (int i = 1; i < n; i++) {
|
||||||
|
if (arr[i] == arr[i - 1]) {
|
||||||
|
currentLen++;
|
||||||
|
} else {
|
||||||
|
maxLen = Math.max(maxLen, currentLen);
|
||||||
|
currentLen = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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.
23
com/study/demo/test3_4.java
Normal file
23
com/study/demo/test3_4.java
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package com.study.demo;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class test3_4 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
int n = scanner.nextInt();
|
||||||
|
int m = scanner.nextInt();
|
||||||
|
int[][] image = new int[n][m];
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
for (int j = 0; j < m; j++) {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
com/study/demo/test3_5.class
Normal file
BIN
com/study/demo/test3_5.class
Normal file
Binary file not shown.
34
com/study/demo/test3_5.java
Normal file
34
com/study/demo/test3_5.java
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package com.study.demo;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class test3_5 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
int n = scanner.nextInt();
|
||||||
|
int[] t = new int[n - 1];
|
||||||
|
int[] s = new int[n];
|
||||||
|
for (int i = 0; i < n - 1; i++) {
|
||||||
|
t[i] = scanner.nextInt();
|
||||||
|
}
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
s[i] = scanner.nextInt();
|
||||||
|
}
|
||||||
|
int x = scanner.nextInt();
|
||||||
|
int y = scanner.nextInt();
|
||||||
|
|
||||||
|
int total = 0;
|
||||||
|
if (x < y) {
|
||||||
|
for (int i = x - 1; i < y - 1; i++) {
|
||||||
|
total += s[i] + t[i];
|
||||||
|
}
|
||||||
|
total += s[y - 1];
|
||||||
|
} else {
|
||||||
|
for (int i = x - 1; i >= y; i--) {
|
||||||
|
total += s[i] + (i > 0 ? t[i - 1] : 0);
|
||||||
|
}
|
||||||
|
total += s[y - 1];
|
||||||
|
}
|
||||||
|
System.out.println(total);
|
||||||
|
}
|
||||||
|
}
|
||||||
27
flake.lock
generated
Normal file
27
flake.lock
generated
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1759070547,
|
||||||
|
"narHash": "sha256-JVZl8NaVRYb0+381nl7LvPE+A774/dRpif01FKLrYFQ=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "647e5c14cbd5067f44ac86b74f014962df460840",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixpkgs-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
21
flake.nix
Normal file
21
flake.nix
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
description = "A Nix-flake-based development environment";
|
||||||
|
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||||
|
outputs = { self, nixpkgs }:
|
||||||
|
let
|
||||||
|
supportedSystems = [ "x86_64-linux" "aarch64-linux" ];
|
||||||
|
forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f {
|
||||||
|
pkgs = import nixpkgs { inherit self system; };
|
||||||
|
});
|
||||||
|
in
|
||||||
|
{
|
||||||
|
devShells = forEachSupportedSystem ({ pkgs }: {
|
||||||
|
default = pkgs.mkShell {
|
||||||
|
packages = with pkgs; [
|
||||||
|
jdk8
|
||||||
|
];
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user