Reputation: 3
Basically, I want to use to put a value into main and set it up so I can use the word/words entered into main so I can use the code.
public static String L33TLanguageSupport(String s) {
Scanner scan =new Scanner (s);
char o = 0;
char O=0;
char e=0, E=0, a=0, A= 0;
return s
.replace(o, (char) 0)
.replace(O,(char) 0)
.replace(e, (char) 3)
.replace(E,(char) 3)
.replace(a, (char)4)
.replace(A, (char)4);
}
public static void main (String[] arg) {
System.out.println(L33TLanguageSupport("cow life" ));
}
Upvotes: 0
Views: 43
Reputation: 82579
You could get the same by doing java main cow life
and then passing in those arguments to the L33tLanguagesupport
object concat'd together.
public static void main(String[] args) {
StringBuilder sb = new StringBuilder();
for(String arg : args) sb.append(arg).append(" ");
System.out.println(sb.toString().trim());
}
Upvotes: 0
Reputation: 85779
You need to read the user input using Scanner
in your desired method, then retrieve the result into a variable and send it to another method.
Adapted from your posted code:
public static String L33TLanguageSupport(String s) {
//remove this from here
//Scanner scan =new Scanner (s);
//do what it must do...
}
public static void main (String[] arg) {
//System.out.println(L33TLanguageSupport("cow life" ));
//creating the scanner to read user input
Scanner scanner = new Scanner(System.in);
//showing a nice message to user
System.out.print("Enter a word: ");
//reading the user input (the whole line until user press Enter key)
String input = scanner.readLine();
//applying the method to user input
String output = L33TLanguageSupport(input);
//showing to user the result of the processing
System.out.println("Result: " + output);
//closing the scanner resources
scanner.close();
}
Upvotes: 1