Ich habe versucht ein Programm zu schreiben, dass mir bei der Eingabe einer Variablen i alle Hexadezimal-zahlen mit i Stellen unter einander hinschreibt, begonnen bei 0. Also will ich wenn ich 2 eingebe diese Ausgabe
00
01
...
ff
und bei 3 diese:
000
001
...
fff
usw. Mein Code macht aber das (bei der Eingabe 2):
0
1
...
f
0
1
...
f
Was kann ich tun ????:L
Hier ist der Code :shock: (auch im Anhang als JAVA-Datei denn er kompiliert tut nur nicht was er soll)
00
01
...
ff
und bei 3 diese:
000
001
...
fff
usw. Mein Code macht aber das (bei der Eingabe 2):
0
1
...
f
0
1
...
f
Was kann ich tun ????:L
Hier ist der Code :shock: (auch im Anhang als JAVA-Datei denn er kompiliert tut nur nicht was er soll)
Java:
package do25;
import java.util.*;
public class do25 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
while (true) {
try {
System.out.println("Bitte Sie geben Zahl ein:");
class Some {
Scanner sc = new Scanner(System.in);
public int i = sc.nextInt();
}
int i = (new Some()).i;
dienst(i);
break;
} catch (InputMismatchException e) {
System.err.println("Geben Sie eine Zahl ein!");
}
}
}
private static void dienst(int nextInt) {
// TODO Auto-generated method stub
for (int k=1;k <= nextInt; k++){
letter(k);
}
}
private static void letter(int j) {
for (j=0; j<=15;j++){
if (j<=9){
System.out.print(j);
} else {
switch (j){
case 10: System.out.print("a"); break;
case 11: System.out.print("b"); break;
case 12: System.out.print("c"); break;
case 13: System.out.print("d"); break;
case 14: System.out.print("e"); break;
case 15: System.out.print("f"); break;
}
}
System.out.println();
}
}
}