Init
This commit is contained in:
commit
cf4af5fc8d
24
.gitignore
vendored
Normal file
24
.gitignore
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# Compiled class file
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# Log file
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# BlueJ files
|
||||||
|
*.ctxt
|
||||||
|
|
||||||
|
# Mobile Tools for Java (J2ME)
|
||||||
|
.mtj.tmp/
|
||||||
|
|
||||||
|
# Package Files #
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.nar
|
||||||
|
*.ear
|
||||||
|
*.zip
|
||||||
|
*.tar.gz
|
||||||
|
*.rar
|
||||||
|
|
||||||
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
|
hs_err_pid*
|
||||||
|
replay_pid*
|
||||||
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
6
.idea/misc.xml
generated
Normal file
6
.idea/misc.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="openjdk-25" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/countDigitsIterative.iml" filepath="$PROJECT_DIR$/countDigitsIterative.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
18
CountDigits.java
Normal file
18
CountDigits.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
public class CountDigits {
|
||||||
|
public int countDigitsIterativ(int n) {
|
||||||
|
int count = 0;
|
||||||
|
while (n != 0) {
|
||||||
|
n /= 10;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int countDigitsRekursiv(int n) {
|
||||||
|
if (n != 0) {
|
||||||
|
n /= 10;
|
||||||
|
return 1 + countDigitsRekursiv(n);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
12
GNUmakefile
Normal file
12
GNUmakefile
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
JAVA_FMT = google-java-format
|
||||||
|
JAVA_FILES = $(shell find . -name '*.java')
|
||||||
|
XML_FMT = xmlindent
|
||||||
|
XML_FILES = $(shell find . -name '*.xml')
|
||||||
|
|
||||||
|
.PHONY: fmt
|
||||||
|
fmt:
|
||||||
|
@echo "Formatting all Java files..."
|
||||||
|
@for f in $(JAVA_FILES); do \
|
||||||
|
echo " $$f"; \
|
||||||
|
$(JAVA_FMT) -i $$f; \
|
||||||
|
done
|
||||||
9
Main.java
Normal file
9
Main.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
CountDigits countDigits = new CountDigits();
|
||||||
|
for (int index = 10; index < 110; index += 10) {
|
||||||
|
System.out.println("Iterativ" + countDigits.countDigitsIterativ(index));
|
||||||
|
System.out.println("Rekursiv" + countDigits.countDigitsRekursiv(index));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
2
README.md
Normal file
2
README.md
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Count digits
|
||||||
|
Count digits teilt die Zahl n durch 10 und gibt danach die zahl zurück als int wie oft die zahl teilbar ist.
|
||||||
11
countDigitsIterative.iml
Normal file
11
countDigitsIterative.iml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
61
flake.lock
generated
Normal file
61
flake.lock
generated
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"flake-parts": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs-lib": "nixpkgs-lib"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1762980239,
|
||||||
|
"narHash": "sha256-8oNVE8TrD19ulHinjaqONf9QWCKK+w4url56cdStMpM=",
|
||||||
|
"owner": "hercules-ci",
|
||||||
|
"repo": "flake-parts",
|
||||||
|
"rev": "52a2caecc898d0b46b2b905f058ccc5081f842da",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "hercules-ci",
|
||||||
|
"repo": "flake-parts",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1762977756,
|
||||||
|
"narHash": "sha256-4PqRErxfe+2toFJFgcRKZ0UI9NSIOJa+7RXVtBhy4KE=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "c5ae371f1a6a7fd27823bc500d9390b38c05fa55",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs-lib": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1761765539,
|
||||||
|
"narHash": "sha256-b0yj6kfvO8ApcSE+QmA6mUfu8IYG6/uU28OFn4PaC8M=",
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "nixpkgs.lib",
|
||||||
|
"rev": "719359f4562934ae99f5443f20aa06c2ffff91fc",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "nixpkgs.lib",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-parts": "flake-parts",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
57
flake.nix
Normal file
57
flake.nix
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
{
|
||||||
|
description = "count digits iterativ";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
flake-parts.url = "github:hercules-ci/flake-parts";
|
||||||
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = inputs@{ flake-parts, ... }:
|
||||||
|
flake-parts.lib.mkFlake { inherit inputs; } {
|
||||||
|
imports = [
|
||||||
|
];
|
||||||
|
systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ];
|
||||||
|
perSystem = { config, self', inputs', pkgs, system, ... }: let
|
||||||
|
|
||||||
|
jdk = pkgs.jdk21.override {
|
||||||
|
};
|
||||||
|
|
||||||
|
buildInputs = [
|
||||||
|
jdk
|
||||||
|
];
|
||||||
|
|
||||||
|
devTools = [
|
||||||
|
pkgs.google-java-format
|
||||||
|
];
|
||||||
|
|
||||||
|
in {
|
||||||
|
devShells.default = pkgs.mkShell {
|
||||||
|
buildInputs = buildInputs ++ devTools;
|
||||||
|
};
|
||||||
|
|
||||||
|
packages = {
|
||||||
|
default = pkgs.stdenv.mkDerivation {
|
||||||
|
pname = "count-digits-iterativ";
|
||||||
|
version = "1.0.0";
|
||||||
|
|
||||||
|
src = ./.;
|
||||||
|
|
||||||
|
nativeBuildInputs = buildInputs ++ [ pkgs.makeWrapper ];
|
||||||
|
|
||||||
|
buildPhase = ''
|
||||||
|
javac -Werror -g:none -deprecation -verbose Main.java
|
||||||
|
'';
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
mkdir -p $out/{bin,lib}
|
||||||
|
cp *.class $out/lib
|
||||||
|
|
||||||
|
makeWrapper ${pkgs.lib.getExe jdk} $out/bin/count-digits-iterativ --add-flags "-cp $out/lib/ Main"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
flake = {
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
1
out/production/countDigitsIterative/.envrc
Normal file
1
out/production/countDigitsIterative/.envrc
Normal file
@ -0,0 +1 @@
|
|||||||
|
use flake .
|
||||||
24
out/production/countDigitsIterative/.gitignore
vendored
Normal file
24
out/production/countDigitsIterative/.gitignore
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# Compiled class file
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# Log file
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# BlueJ files
|
||||||
|
*.ctxt
|
||||||
|
|
||||||
|
# Mobile Tools for Java (J2ME)
|
||||||
|
.mtj.tmp/
|
||||||
|
|
||||||
|
# Package Files #
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.nar
|
||||||
|
*.ear
|
||||||
|
*.zip
|
||||||
|
*.tar.gz
|
||||||
|
*.rar
|
||||||
|
|
||||||
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
|
hs_err_pid*
|
||||||
|
replay_pid*
|
||||||
3
out/production/countDigitsIterative/.idea/.gitignore
generated
vendored
Normal file
3
out/production/countDigitsIterative/.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
6
out/production/countDigitsIterative/.idea/misc.xml
generated
Normal file
6
out/production/countDigitsIterative/.idea/misc.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="openjdk-25" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
8
out/production/countDigitsIterative/.idea/modules.xml
generated
Normal file
8
out/production/countDigitsIterative/.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/countDigitsIterative.iml" filepath="$PROJECT_DIR$/countDigitsIterative.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
12
out/production/countDigitsIterative/GNUmakefile
Normal file
12
out/production/countDigitsIterative/GNUmakefile
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
JAVA_FMT = google-java-format
|
||||||
|
JAVA_FILES = $(shell find . -name '*.java')
|
||||||
|
XML_FMT = xmlindent
|
||||||
|
XML_FILES = $(shell find . -name '*.xml')
|
||||||
|
|
||||||
|
.PHONY: fmt
|
||||||
|
fmt:
|
||||||
|
@echo "Formatting all Java files..."
|
||||||
|
@for f in $(JAVA_FILES); do \
|
||||||
|
echo " $$f"; \
|
||||||
|
$(JAVA_FMT) -i $$f; \
|
||||||
|
done
|
||||||
2
out/production/countDigitsIterative/README.md
Normal file
2
out/production/countDigitsIterative/README.md
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Count digits
|
||||||
|
Count digits teilt die Zahl n durch 10 und gibt danach die zahl zurück als int wie oft die zahl teilbar ist.
|
||||||
11
out/production/countDigitsIterative/countDigitsIterative.iml
Normal file
11
out/production/countDigitsIterative/countDigitsIterative.iml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
61
out/production/countDigitsIterative/flake.lock
generated
Normal file
61
out/production/countDigitsIterative/flake.lock
generated
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"flake-parts": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs-lib": "nixpkgs-lib"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1762980239,
|
||||||
|
"narHash": "sha256-8oNVE8TrD19ulHinjaqONf9QWCKK+w4url56cdStMpM=",
|
||||||
|
"owner": "hercules-ci",
|
||||||
|
"repo": "flake-parts",
|
||||||
|
"rev": "52a2caecc898d0b46b2b905f058ccc5081f842da",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "hercules-ci",
|
||||||
|
"repo": "flake-parts",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1762977756,
|
||||||
|
"narHash": "sha256-4PqRErxfe+2toFJFgcRKZ0UI9NSIOJa+7RXVtBhy4KE=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "c5ae371f1a6a7fd27823bc500d9390b38c05fa55",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs-lib": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1761765539,
|
||||||
|
"narHash": "sha256-b0yj6kfvO8ApcSE+QmA6mUfu8IYG6/uU28OFn4PaC8M=",
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "nixpkgs.lib",
|
||||||
|
"rev": "719359f4562934ae99f5443f20aa06c2ffff91fc",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "nixpkgs.lib",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-parts": "flake-parts",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
57
out/production/countDigitsIterative/flake.nix
Normal file
57
out/production/countDigitsIterative/flake.nix
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
{
|
||||||
|
description = "count digits iterativ";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
flake-parts.url = "github:hercules-ci/flake-parts";
|
||||||
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = inputs@{ flake-parts, ... }:
|
||||||
|
flake-parts.lib.mkFlake { inherit inputs; } {
|
||||||
|
imports = [
|
||||||
|
];
|
||||||
|
systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ];
|
||||||
|
perSystem = { config, self', inputs', pkgs, system, ... }: let
|
||||||
|
|
||||||
|
jdk = pkgs.jdk21.override {
|
||||||
|
};
|
||||||
|
|
||||||
|
buildInputs = [
|
||||||
|
jdk
|
||||||
|
];
|
||||||
|
|
||||||
|
devTools = [
|
||||||
|
pkgs.google-java-format
|
||||||
|
];
|
||||||
|
|
||||||
|
in {
|
||||||
|
devShells.default = pkgs.mkShell {
|
||||||
|
buildInputs = buildInputs ++ devTools;
|
||||||
|
};
|
||||||
|
|
||||||
|
packages = {
|
||||||
|
default = pkgs.stdenv.mkDerivation {
|
||||||
|
pname = "count-digits-iterativ";
|
||||||
|
version = "1.0.0";
|
||||||
|
|
||||||
|
src = ./.;
|
||||||
|
|
||||||
|
nativeBuildInputs = buildInputs ++ [ pkgs.makeWrapper ];
|
||||||
|
|
||||||
|
buildPhase = ''
|
||||||
|
javac -Werror -g:none -deprecation -verbose Main.java
|
||||||
|
'';
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
mkdir -p $out/{bin,lib}
|
||||||
|
cp *.class $out/lib
|
||||||
|
|
||||||
|
makeWrapper ${pkgs.lib.getExe jdk} $out/bin/count-digits-iterativ --add-flags "-cp $out/lib/ Main"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
flake = {
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user