From af1ea3e24e9711b84c9665efe7c70599da631125 Mon Sep 17 00:00:00 2001 From: dichgrem Date: Thu, 30 Oct 2025 14:30:50 +0800 Subject: [PATCH] start:java8 --- com/study/demo/Demo.java | 7 +++++++ com/study/demo/test1_1.java | 13 +++++++++++++ com/study/demo/test1_2.java | 16 ++++++++++++++++ com/study/demo/test1_3.java | 19 +++++++++++++++++++ com/study/demo/test2_1.java | 14 ++++++++++++++ com/study/demo/test2_2.java | 14 ++++++++++++++ com/study/demo/test2_3.java | 12 ++++++++++++ com/study/demo/test2_4.java | 14 ++++++++++++++ com/study/demo/test2_5.java | 19 +++++++++++++++++++ com/study/demo/test3_1.class | Bin 0 -> 1101 bytes com/study/demo/test3_1.java | 22 ++++++++++++++++++++++ com/study/demo/test3_2.class | Bin 0 -> 785 bytes com/study/demo/test3_2.java | 23 +++++++++++++++++++++++ com/study/demo/test3_3.class | Bin 0 -> 821 bytes com/study/demo/test3_3.java | 25 +++++++++++++++++++++++++ com/study/demo/test3_4.class | Bin 0 -> 1144 bytes com/study/demo/test3_4.java | 23 +++++++++++++++++++++++ com/study/demo/test3_5.class | Bin 0 -> 999 bytes com/study/demo/test3_5.java | 34 ++++++++++++++++++++++++++++++++++ flake.lock | 27 +++++++++++++++++++++++++++ flake.nix | 21 +++++++++++++++++++++ 21 files changed, 303 insertions(+) create mode 100644 com/study/demo/Demo.java create mode 100644 com/study/demo/test1_1.java create mode 100644 com/study/demo/test1_2.java create mode 100644 com/study/demo/test1_3.java create mode 100644 com/study/demo/test2_1.java create mode 100644 com/study/demo/test2_2.java create mode 100644 com/study/demo/test2_3.java create mode 100644 com/study/demo/test2_4.java create mode 100644 com/study/demo/test2_5.java create mode 100644 com/study/demo/test3_1.class create mode 100644 com/study/demo/test3_1.java create mode 100644 com/study/demo/test3_2.class create mode 100644 com/study/demo/test3_2.java create mode 100644 com/study/demo/test3_3.class create mode 100644 com/study/demo/test3_3.java create mode 100644 com/study/demo/test3_4.class create mode 100644 com/study/demo/test3_4.java create mode 100644 com/study/demo/test3_5.class create mode 100644 com/study/demo/test3_5.java create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/com/study/demo/Demo.java b/com/study/demo/Demo.java new file mode 100644 index 0000000..cd317cd --- /dev/null +++ b/com/study/demo/Demo.java @@ -0,0 +1,7 @@ +package com.study.demo; + +public class Demo { + public static void main(String [] args) { + System.out.println("HelloWorld!"); + } +} diff --git a/com/study/demo/test1_1.java b/com/study/demo/test1_1.java new file mode 100644 index 0000000..5f0e51d --- /dev/null +++ b/com/study/demo/test1_1.java @@ -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(); + } +} diff --git a/com/study/demo/test1_2.java b/com/study/demo/test1_2.java new file mode 100644 index 0000000..31d5ee0 --- /dev/null +++ b/com/study/demo/test1_2.java @@ -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] + " "); + } + } +} + diff --git a/com/study/demo/test1_3.java b/com/study/demo/test1_3.java new file mode 100644 index 0000000..05189ee --- /dev/null +++ b/com/study/demo/test1_3.java @@ -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); + } +} + diff --git a/com/study/demo/test2_1.java b/com/study/demo/test2_1.java new file mode 100644 index 0000000..bf44c29 --- /dev/null +++ b/com/study/demo/test2_1.java @@ -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); + } +} diff --git a/com/study/demo/test2_2.java b/com/study/demo/test2_2.java new file mode 100644 index 0000000..f3b570f --- /dev/null +++ b/com/study/demo/test2_2.java @@ -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); + } +} \ No newline at end of file diff --git a/com/study/demo/test2_3.java b/com/study/demo/test2_3.java new file mode 100644 index 0000000..f1ae9e3 --- /dev/null +++ b/com/study/demo/test2_3.java @@ -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); + } +} \ No newline at end of file diff --git a/com/study/demo/test2_4.java b/com/study/demo/test2_4.java new file mode 100644 index 0000000..0f0ced7 --- /dev/null +++ b/com/study/demo/test2_4.java @@ -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); + } +} \ No newline at end of file diff --git a/com/study/demo/test2_5.java b/com/study/demo/test2_5.java new file mode 100644 index 0000000..87d354a --- /dev/null +++ b/com/study/demo/test2_5.java @@ -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); + } +} diff --git a/com/study/demo/test3_1.class b/com/study/demo/test3_1.class new file mode 100644 index 0000000000000000000000000000000000000000..8a09b0324f56277c50f6d35e78b7f55adb246df3 GIT binary patch literal 1101 zcmaJ=O-~b16g_V`(>EQ4j{*hMq9CFz*p7UN9~4k9#wJLOH3Y)K44nxXY-gG>V`T5j zmHq?6hP5n8BE}!!!o9!3Ju%k%+7he~XK~+s_uhBjx#zz5_WSc!0MmG+p$kJC!x3D? zhz1GQgc%jv>l`;Ua105PP?1zICfsphZfZy&&0%odVhCp(*YW2WLW$%mgS_NfHbdvK z^~x zlN?jTg=3mQ%X>kkU_W*QobKB@{?yBfv;fl)MK?pV4jlMS(a0A}*R?Agw{^_mjwraR z;~wtom_>%6|6dM^fm5{XijFx@FJNFp!e7ww01t_TjzugH{eo9AcKpEFH7vX28BG=p zU8jJ#&278jGxVI(DTB0;rBuDz@r-BGzfUUIW~l|EAxvv%cgMG>N)j^08X^)x)-4B3 zgjt4x#JLF}Fn8@Ye%2*oG%4Z`@&fWtf&QXGKw-07wq1)Mp2#N8OsuIE)uoyjwv6*X z^{Vfk^wyg=3rvVgS!hDc&O=_sFgoeoicg{`(cH=Q&~8x7j8`%pDwMhS7i}dpBgf?U9-^t3EP}bWGTX2HY=o8K9!4pV zo>9oA;<6Q!t#q#G#G1uFPB1195IzE5KZGg{RS_X*+4=~zTib`y-ByKOMSB$;^-I1B z+EShNJaq~B*V>>`w-JhI)L|P&X&py9z3C2QsOAY}pVNMgbTFy8ceK8zR{QDn8q^v& x3daD)1;%la^f^Y)FG%bdNwL&0(wdhzE^)+bq*TkfP$SMUcuY4lT&^>{@(1=_>remy literal 0 HcmV?d00001 diff --git a/com/study/demo/test3_1.java b/com/study/demo/test3_1.java new file mode 100644 index 0000000..ef5f27b --- /dev/null +++ b/com/study/demo/test3_1.java @@ -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 ? "" : " ")); + } + } +} diff --git a/com/study/demo/test3_2.class b/com/study/demo/test3_2.class new file mode 100644 index 0000000000000000000000000000000000000000..5ba259a98cd14fe1697094d6f0ae05bb3403065a GIT binary patch literal 785 zcmZuuO>fgc5Pj>|-o`bw`EW=|3bcGBDTxuFNKoKVBt%4Lky2GcJ%Hm_#U-{wvPSgY zU&4hmJ+u-aegMCO6P&nIK$&%^Qlwh;zS*}kZ{Li+{`vR?z%4Wkq*35FlSUCG0}5v3 za#n8324-=N<2=U&2K}xd`rzpu>27+iV91?dm_b=@{g>U@8VN5TUN&hRw&+K8D;&gvy7Zi2k)c>Q@j$lEL+`C< zg>)ayk)%^mOz~LgDGh2YluK-q{xO;~1~REn2GmNcx`sJS&|j2~0-7TxX*Fp#OUMYd z+8)>k3TXPY>W3tioW>NzGW91^aKhmyD9?6~+Jo9&*oAhl{MlHh?~a;kYL-@hhfLkl zt$7vWz1~ ZFU?^exnEG&KJvezF~S*YKA&7~{RLyjpMU@W literal 0 HcmV?d00001 diff --git a/com/study/demo/test3_2.java b/com/study/demo/test3_2.java new file mode 100644 index 0000000..6c23487 --- /dev/null +++ b/com/study/demo/test3_2.java @@ -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); + } +} diff --git a/com/study/demo/test3_3.class b/com/study/demo/test3_3.class new file mode 100644 index 0000000000000000000000000000000000000000..0f74550c92bbcc2672cb691175d5fb9d65ed6790 GIT binary patch literal 821 zcmZuuL2nXK5dI##-3QB7O6gKms7?`NOC0a(SV1`Trp**LD^nuZ9j z%Oj^@9ycU*Q^PGR2rLTRW>6oyz8gGch?@B(1ApG@I1I^}>pSbA*K!80?N*l%?%A%- zkTJJvd-glq>e~K})d&Wzzq2M2ry7CXep9#mW4^#0QXsIzpf!5opzXYHWfeVehCz9| zT#_|(B%m{-#`VI$?OKht?fcF^;I58)FeM?cV;Kd3`#Op!>9FuXU`5A6lu1py=UKxb z>>OAf$Lm>tsxwSaG;Xx^oOZyFzC<`fWUKlgyKyiK9FK50tZ^}_+q0^EKMZJE$M)73 zvgV}$xd!1o`$5&GezZ?2ePtq~ZU?&rd-gtqVpgj%9PNcfo%DG{`<(PikCUnWKQOiE zOH!BgakH9lVgYe_ars5S=M{xlR70hpSv1rV{k&6pkN8Mo zhe#USP(DE&^F}J={P>F;K^XiPF)1rDmi3IpfJ7t^BQK6wnrWVHOJoZqa)nrrNb*aH z)-i)7(%2+y8yW0k4t->iq6&*p&*`cN%m}2Jz%1?H6zMa>7-QMQDHIyo828Qm1~-nQ Az5oCK literal 0 HcmV?d00001 diff --git a/com/study/demo/test3_3.java b/com/study/demo/test3_3.java new file mode 100644 index 0000000..1b1d23b --- /dev/null +++ b/com/study/demo/test3_3.java @@ -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); + } +} diff --git a/com/study/demo/test3_4.class b/com/study/demo/test3_4.class new file mode 100644 index 0000000000000000000000000000000000000000..04b1e71c03083b1386121824c045f1b18400d7d2 GIT binary patch literal 1144 zcmaJ>O-~b16g{tuoU2khzENn{pR_fJb zD;MB7CP*R2ZBoNA$)F{(g?!3cas`*}J3IdP%ZX9Jq@x`j46Olc!FSVUGG%$5ljpdj z<1X$Az?6<@%#g^9jf9R_klwD-G8PJM+II3f?&ARi7+9~!=XES#k)-H&h(|h>#M?Sk z*^Ig47wlcrb~0JBE{GxWk9Bo(+e!Hh?dR;6ssYf=nrmc%PewRa=EU-vHz!NGJHA7x zkZ{td`A7^2FIT8DOfz)H&us{gx#zs`6CP=zVI?SL3zYvOIwpmP6f2i=JewgJPYj+J zTHP(ejnrRwVxs@StA6(H-a6uEiHT9p2~SAbdCX!TK|k%G53O{V#TBA?(K(=K&{IrI zkM8nN8SFD9G%<=wt%wG6p__7ovS*OMsrTU!q4fiV%aB%vOOR(pn2W}~K?zMs;Yrz$ zqkHHNPb!8I+k?>~8S^!A-CxzG?ma?LQ7Gp?pJ>hzJy3XR~F(!f%pYPDCcOT?=V7JFrd*s8!-T# zzQ-my-#X^$d6~Lv?$hI25w#2r8?fs{;85 oA$A0fRq1EIkAvvkaYQ*{RkH3>CtT}rT&keCLMj+82g-Z@0Qwa6od5s; literal 0 HcmV?d00001 diff --git a/com/study/demo/test3_4.java b/com/study/demo/test3_4.java new file mode 100644 index 0000000..63d2a91 --- /dev/null +++ b/com/study/demo/test3_4.java @@ -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(); + } + } +} diff --git a/com/study/demo/test3_5.class b/com/study/demo/test3_5.class new file mode 100644 index 0000000000000000000000000000000000000000..596c796468b032e74f38b0cf44def7f27da325e0 GIT binary patch literal 999 zcmZ`%O-~b16g_Xg-gFp&0*?OXShY zt{*V;C)cu@?h7|va)XU@F0A^&#=In6%7t#>*?o5_!gGw%ZQMZ8#uTPGW^CNVEM-xsl+)W` zt+sRip;soqEK;;e^egF1uvH7GO3y9N zGYlp#49N0%;Jpkp0o_M^Bx$u$qkUWG0X3>E)ElKq`e)pvu_ZwzNe4c)6fK!i5bjyFA`ZY|aNoqri>>M>^k=n9EHj6kOq6d%BhcyV~3H=-ccun>V zhVYh{btG^|_6tVw9b@=G)99ufUcqjX%ixG}^e~QIdTAI(5XVs15&D|Mik%NL79mDD ZkD;^w#1%#nT*Op~euS8ueqU6tI03=TzViS8 literal 0 HcmV?d00001 diff --git a/com/study/demo/test3_5.java b/com/study/demo/test3_5.java new file mode 100644 index 0000000..574959b --- /dev/null +++ b/com/study/demo/test3_5.java @@ -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); + } +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..3d8d012 --- /dev/null +++ b/flake.lock @@ -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 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..3ca1e3b --- /dev/null +++ b/flake.nix @@ -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 + ]; + }; + }); + }; +} +