Pete1

Untitled

Mar 17th, 2016
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. public class Problem10CharacterMultiplier {
  5. public static void main(String[] args) {
  6. Scanner console = new Scanner(System.in);
  7. String firstString = console.next("\\w+");
  8. String secondString = console.next("\\w+");
  9.  
  10. System.out.println(findingProduct(firstString, secondString));
  11. }
  12.  
  13. static int findingProduct(String firstString, String secondString) {
  14. int product = 0;
  15. if (firstString.length() == secondString.length()) {
  16. for (int i = 0; i < firstString.length(); i++) {
  17. product += firstString.charAt(i) * secondString.charAt(i);
  18. }
  19. } else if (firstString.length() > secondString.length()) {
  20. for (int i = 0; i < secondString.length() ; i++) {
  21. product+= firstString.charAt(i) * secondString.charAt(i);
  22. }
  23. for (int i = secondString.length() ; i < firstString.length() ; i++) {
  24. product+= firstString.charAt(i);
  25. }
  26.  
  27. }else {
  28. for (int i = 0; i < firstString.length() ; i++) {
  29. product+= firstString.charAt(i) * secondString.charAt(i);
  30. }
  31. for (int i = firstString.length() ; i < secondString.length() ; i++) {
  32. product+= secondString.charAt(i);
  33. }
  34. }
  35. return product;
  36. }
  37. }
Add Comment
Please, Sign In to add comment