Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object App {
- class Polinom(koeficijenti: Array[Int]) {
- def *(A: Polinom): Polinom = {
- val n = this.level() + A.level() - 1
- val P1 = this.getK()
- val P2 = A.getK()
- var res = Array[Int]()
- for(i <- 0 until n)
- res = res :+ 0
- for(i <- 0 until this.level(); j <- 0 until A.level())
- res(i + j) += P1(i) * P2(j)
- new Polinom(res)
- }
- def level(): Int = this.koeficijenti.length
- def getK(): Array[Int] = koeficijenti
- }
- def main(args: Array[String]) {
- var A = new Polinom(Array(1, 2, 3))
- var B = new Polinom(Array(3, 2, 1))
- var C = A * B
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement