Compare commits
3 Commits
4c8c038eec
...
84b40cc8e9
Author | SHA1 | Date |
---|---|---|
Giacomo R. | 84b40cc8e9 | |
Giacomo R. | f4b0fa1846 | |
Giacomo R. | 3ed4f15666 |
File diff suppressed because it is too large
Load Diff
|
@ -1,8 +1,8 @@
|
|||
build.xml.data.CRC32=7a406286
|
||||
build.xml.script.CRC32=761ebeaf
|
||||
build.xml.stylesheet.CRC32=f85dc8f2@1.99.0.48
|
||||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
||||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
||||
nbproject/build-impl.xml.data.CRC32=7a406286
|
||||
nbproject/build-impl.xml.script.CRC32=c26710d0
|
||||
nbproject/build-impl.xml.stylesheet.CRC32=d549e5cc@1.99.0.48
|
||||
build.xml.data.CRC32=7a406286
|
||||
build.xml.script.CRC32=761ebeaf
|
||||
build.xml.stylesheet.CRC32=f85dc8f2@1.99.0.48
|
||||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
||||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
||||
nbproject/build-impl.xml.data.CRC32=7a406286
|
||||
nbproject/build-impl.xml.script.CRC32=e96aa72e
|
||||
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.106.0.48
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
package ricorsione;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Collezione 2 di metodi ricorsivi utilizzata per gli esercizi per il 6/6/23
|
||||
* @author radaelli11353
|
||||
*/
|
||||
public class Ricorsione2 {
|
||||
public static ArrayList<Integer> scomposizioneFattoriPrimi(int n) {
|
||||
ArrayList<Integer> fattori = new ArrayList<>();
|
||||
|
||||
for (int i = 2; i <= n; i++) {
|
||||
if (n % i == 0) {
|
||||
fattori.add(i);
|
||||
n = n / i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (n > 1) {
|
||||
fattori.addAll(scomposizioneFattoriPrimi(n));
|
||||
}
|
||||
|
||||
return fattori;
|
||||
}
|
||||
|
||||
public static String reverse(String text) {
|
||||
if (text.length() <= 1) {
|
||||
return text;
|
||||
}
|
||||
return reverse(text.substring(1)) + text.charAt(0);
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
int numero = 4;
|
||||
ArrayList<Integer> fattoriPrimi = scomposizioneFattoriPrimi(numero);
|
||||
|
||||
System.out.println("Fattori primi di " + numero + ":");
|
||||
for (int fattore : fattoriPrimi) {
|
||||
System.out.println(fattore);
|
||||
}
|
||||
|
||||
System.out.println("----------------------");
|
||||
|
||||
String input = "Hello!";
|
||||
String reversed = reverse(input);
|
||||
|
||||
System.out.println("Originale: " + input);
|
||||
System.out.println("Invertita: " + reversed);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue