From 09c939386c591e926b0705d8e9d80f7dc6307672 Mon Sep 17 00:00:00 2001 From: qxo <49526356@qq.com> Date: Sun, 29 Oct 2023 10:52:37 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20imporve=20MathGame=20=E5=8A=A0=E5=85=A5?= =?UTF-8?q?sleep=E5=8F=8A=E6=94=B9=E4=B8=BA=E5=A4=9A=E5=B1=82=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E4=BB=A5=E6=A8=A1=E6=8B=9F=E5=AE=9E=E9=99=85=E6=83=85?= =?UTF-8?q?=E5=86=B5=EF=BC=8C=E6=96=B9=E4=BE=BF=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- math-game/src/main/java/demo/MathGame.java | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/math-game/src/main/java/demo/MathGame.java b/math-game/src/main/java/demo/MathGame.java index 82466227fea..9269b18b7fe 100644 --- a/math-game/src/main/java/demo/MathGame.java +++ b/math-game/src/main/java/demo/MathGame.java @@ -21,7 +21,7 @@ public static void main(String[] args) throws InterruptedException { public void run() throws InterruptedException { try { int number = random.nextInt()/10000; - List primeFactors = primeFactors(number); + List primeFactors = primeFactorsByPass3(number); print(number, primeFactors); } catch (Exception e) { @@ -29,7 +29,7 @@ public void run() throws InterruptedException { } } - public static void print(int number, List primeFactors) { + public static void print(final int number, final List primeFactors) { StringBuffer sb = new StringBuffer(number + "="); for (int factor : primeFactors) { sb.append(factor).append('*'); @@ -40,7 +40,24 @@ public static void print(int number, List primeFactors) { System.out.println(sb); } + public List primeFactorsByPass3(final int number) { + return primeFactorsByPass2(number); + } + + public List primeFactorsByPass2(final int number) { + return primeFactorsByPass1(number); + } + + public List primeFactorsByPass1(final int number) { + return primeFactors(number); + } + public List primeFactors(int number) { + try { + Thread.sleep(5); + } catch (final InterruptedException ex) { + throw new IllegalStateException (ex); + } if (number < 2) { illegalArgumentCount++; throw new IllegalArgumentException("number is: " + number + ", need >= 2");