Methode

Siisii92

Mitglied
Java:
import java.util.Scanner;
public class test1{
    
        public static void main(String[] args) {
        
            Scanner sc=new Scanner(System.in);
            System.out.println("auswahl?");
            int auswahl=sc.nextInt();
            
        switch(auswahl){
        
        case 1:
            System.out.println("wort1 ?"); 
            String wort1= sc.nextLine();
            System.out.println("wort2 ?"); 
            String wort2= sc.nextLine();
            System.out.println(hinzufugn(wort1,wort2));                        break;
            
        case 2:    break;
        default: System.out.println("Programm beenden");   
            
        }
        sc.close();
        }
        
        public static  String hinzufugn(String wort1,String wort2) {
            
            int zaehler=0;
            String wort_paar = "";
            wort_paar=wort_paar+wort1+wort2;
            zaehler++;
            if (zaehler>50) { String meldung="mehr als 100"; return meldung;}
            else {    return wort_paar;}
            
        }
}
 
G

Gelöschtes Mitglied 65838

Gast
du speicherst deine wortpaare nirgendsd

mach ein array mit 100 plätzen und falls das array an der 100sten stelle voll ist gibst du eine meldung aus dass es voll ist
 

Siisii92

Mitglied
[CODE lang="java" title="was kann hier als return schreiben?"]public class test1{

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);
System.out.println("auswahl?");
int auswahl=sc.nextInt();

switch(auswahl){

case 1:
System.out.println("wort1 ?");
String wort1= sc.next();
System.out.println("wort2 ?");
String wort2= sc.next();
System.out.println(hinzufugn(wort1,wort2)); break;

case 2: break;
default: System.out.println("Programm beenden");

}
sc.close();
}

public static String hinzufugn(String wort1,String wort2) {

int zahl=0;
String []worter=new String[100];
worter[zahl]=wort1+""+wort2;
zahl++;
if (zahl==100) { String meldung="mehr als 100"; return meldung;}
else { return worter;}

}
}[/CODE]
 
G

Gelöschtes Mitglied 65838

Gast
meines erachtens kompiliert der code nicht ...

du kannst keinen string zurück geben und das andere mal ein string array...
if ( zahl == 100 ) sysout ( " merh als hundert " )
else ( array füg hinzu )

das array muss natürlich außerhalb gespeichert werden
 

Siisii92

Mitglied
[CODE lang="java" title="etwas ist noch falsch :("]Scanner sc=new Scanner(System.in);
System.out.println("auswahl?");
int auswahl=sc.nextInt();
String[] worter=new String [100];
int zahl=0;
String meldung="mehr als 100";
String result = " ";

do {
menue();



switch(auswahl){

case 1: {
System.out.println("wort1 ?");
String wort1= sc.next();
System.out.println("wort2 ?");
String wort2= sc.next();
worter[zahl]=wort1+""+wort2;
zahl++;
if(zahl==100) System.out.print(meldung);
else if(zahl<100)
{ for (int i=0;i<zahl;i++) {
result = worter;
}
System.out.println(result);
}
break;
} [/CODE]
 

Oben