I have to do this task for my school where I have to use a method in order to get my Name initials which is M K. I don't know how I can get these initials in this method. The heigt has to be n/2 and the width n/4.Here ist an example picture enter image description here
Here is my current code:
public class Initials {
static Scanner sc = new Scanner (System.in);
public static void main(String[] args){
char [][] feld = createfield ('m','k');
for (int i = 0; i< feld.length;i++) {
for (int j =0; j<feld[i].length;j++) {
System.out.println (feld[i][j]);
} System.out.println();
}
}
public static char[][] createfield(char firstname, char lastname ) {
System.out.println ("Parameter for n ");
int n = sc.nextInt();
char[][] letter = new char [n][n];
int heigt = n/2 ;
int width = n/4 ;
for (int i=0;i< letter;i++) {
for (int j =0;j< letter[i].length;j++) {
letter [i][j] = ' ';
}
} for (int i=0;i <heigt;i++) {
for (int j = 0;j<width;j++) {
letter [2+i][1] = '+'; // For initial M und K
}
} return letter;
}
} ```
Aucun commentaire:
Enregistrer un commentaire