Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
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();
}
}
rant
can anyone resolve issues on this code