-2
priya23
3y

import java.util.Scanner;

class node {

int coeff;
int power;
node next;

node() {
coeff = power = 0;
next = null;
}
// node(int c,int p){}

}

class polynomial {
private node head;

polynomial() {
head = null;
}

void append(int co, int pow) {
node n = new node();
n.coeff = co;
n.power = pow;
n.next = null;
if (head == null)
head = n;
else {
node temp = head;
while (temp.next != null)
temp = temp.next;
temp.next = n;
}
}

void display() {
node ptr = head;
if (head.next == null)
System.out.print(ptr.coeff + "x^" + ptr.power + "\n");
else {
while (ptr.next != null) {
System.out.print(ptr.coeff + "x^" + ptr.power + "+");

ptr = ptr.next;
}
System.out.print(ptr.coeff+ "x^" + ptr.power + "\n");
}
}

void mul(int numb) {
node temp = head;
while (temp != null) {
temp.coeff = temp.coeff * numb;
temp = temp.next;
}
}
}

public class polynode {

public static void main(String[] args) {
int imp = 0;
int coeff, power;
polynomial p = new polynomial();
Scanner s = new Scanner(System.in);
do {
coeff = s.nextInt();
power = s.nextInt();
imp = s.nextInt();
p.append(coeff, power);
} while (imp != 0);
p.display();
int scalar = s.nextInt();
p.mul(scalar);
s.close();
p.display();

}

}

Comments
  • 1
    Devrant is not a Java Compiler
  • 0
    1. We don't come here to work on your shitty code. We come here to get rest from it and complain about the dev life. You're disturbing everyone's work/life balance. And gods know it is already shaky
    2. If you can't find correct sources to solve your code issues - you might want to reconsider your career choices
Add Comment