Calling the method - new to this
I am writing a program to collate two inputted strings of text e.g.
"google" "chrome" becomes "gcohorgmlee" (you can assume that the letters
are equal length).
import java.util.Scanner;
public class Collate{
String result;
String a;
String b;
public void main(String[] args){
System.out.printf("Enter 1st word: ");
Scanner in1 = new Scanner(System.in);
a = in1.next();
System.out.printf("Enter second word: ");
Scanner in2 = new Scanner(System.in);
b = in2.next();
}
public String collate(String a, String b){
String accumulator;
this.a = a;
this.b = b;
for(int i = 0; i < a.length(); i++)
{
result += a.charAt(i);
result += b.charAt(i);
}
return (result);
}
}
I am stuck however on how to call the method (collate). I am very new to
java and hardly know anything so some pointers and help would be greatly
appreciated! Many thanks, Miten
No comments:
Post a Comment