-
Notifications
You must be signed in to change notification settings - Fork 0
/
Number16.java
59 lines (58 loc) · 1.74 KB
/
Number16.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import java.util.*;
public class Number16 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String p;
int i,n=0,po=0,n1=0,po1=0,j=0;
System.out.println("Enter the equation to find the differentiation");
p=sc.nextLine();
p=p.toLowerCase();
for(i=0;i<p.length();i++)
{
if(p.charAt(i)=='x')
{
n=Integer.parseInt(p.substring(0,i));
po=p.charAt(i+2)-'0';
}
if(p.charAt(i)=='+')
j=i;
else if(p.charAt(i)=='y')
{
n1=Integer.parseInt(p.substring((j+1),i));
po1=p.charAt(i+2)-'0';
}
}
System.out.print("Derivative of the given equation: ");
if(po==1&&po1==1)
System.out.println((n*po)+(n1*po1));
else if(po==0&&po1==0)
System.out.println(0);
else if(po==0&&po1==1)
System.out.println(n1*po1);
else if(po==1&&po1==0)
System.out.println(n*po);
else if(po>1&&po1==0)
System.out.println((n*po)+"x^"+(po-1));
else if(po==0&&po1>1)
System.out.println((n1*po1)+"y^"+(po1-1));
else if(po>1&&po1==1)
System.out.println((n*po)+"x^"+(po-1)+" + "+(n1*po1));
else if(po==1&&po1>1)
System.out.println((n*po)+" + "+(n1*po1)+"y^"+(po1-1));
else
System.out.println(((n*po)+"x^"+(po-1))+" + "+((n1*po1)+"y^"+(po1-1)));
System.out.println("After integration we got "+p+" , hence proved.");
System.out.println("Do you Want to solve the differential equation for any value of x and y? Enter Yes or No");
p=sc.next();
if(p.equals("Yes"))
{
System.out.println("Enter the value of x and y:");
i=sc.nextInt();
j=sc.nextInt();
System.out.print("Value of the differential equation :");
System.out.println((int)((n*po)*Math.pow(i,(po-1))));
}
else
System.out.println("Terminated");
}
}