# Cow Multiplication

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
 This problem has been solved by Eric.

 Sorter: Eric USACO 2008 February Bronze http://acm.pku.edu.cn/JudgeOnline/problem?id=3673

Judging Olympiad is problem number 3673 on the Peking University ACM site.

## Problem Information

Problem Name: Cow Multiplication
Problem Number on PKU: 3673
Synopsis: A pairwise multiplication of two integers.

## Solver Information

Solver: Eric Hong
Date: September 21, 2008

None.

## General Strategy

1. Using Scanner, take the input.
2. Add the products of digits in two String using nested for loops.

## Solution

```import java.util.*;

public class Main
{
public static Scanner in;

public static void main(String[] args)
{
in = new Scanner(System.in);
doStuff();
}

public static void doStuff()
{
String s = in.next();
String t = in.next();
solve(s, t);
}

public static void solve(String s, String t)
{
int len1 = s.length();
int len2 = t.length();

int sum = 0;

for (int i = 0; i < len1; i++)
{
int num1 = s.charAt(i) - '0';

for (int j = 0; j <len2; j++)
{
int num2 = t.charAt(j) - '0';
sum += (num1 * num2);
}
}

System.out.println(sum);
}
}
```