Click here to Skip to main content
15,440,771 members
Home / Discussions / Java
   

Java

 
QuestionRealm EJB in Wildfly Pin
Andy_Bell31-Oct-20 0:55
MemberAndy_Bell31-Oct-20 0:55 
AnswerRe: Realm EJB in Wildfly Pin
Richard MacCutchan31-Oct-20 1:07
mveRichard MacCutchan31-Oct-20 1:07 
GeneralRe: Realm EJB in Wildfly Pin
Andy_Bell31-Oct-20 9:01
MemberAndy_Bell31-Oct-20 9:01 
GeneralRe: Realm EJB in Wildfly Pin
Andy_Bell11-Nov-20 23:46
MemberAndy_Bell11-Nov-20 23:46 
Questionanyone know how a program would be written out for this Pin
Member 1497788728-Oct-20 9:53
MemberMember 1497788728-Oct-20 9:53 
AnswerRe: anyone know how a program would be written out for this Pin
Richard MacCutchan28-Oct-20 9:58
mveRichard MacCutchan28-Oct-20 9:58 
GeneralRe: anyone know how a program would be written out for this Pin
Richard MacCutchan28-Oct-20 10:27
mveRichard MacCutchan28-Oct-20 10:27 
QuestionWrite a program using for loop that computes sinx and cosx by using the following power series- sinx=x-x^3/3!+x^5/5!-x^7/7!+.... cosx=1-x^2/2!+x^4/4!-x^6/6!+..... Note-(Here ! is used for factorial of that number and ^ for "power of" Pin
User 1494142126-Oct-20 20:56
MemberUser 1494142126-Oct-20 20:56 
The question is this-:
Write a program using for loop that computes sinx and cosx by using the following power series-
sinx=x-x^3/3!+x^5/5!-x^7/7!+....
cosx=1-x^2/2!+x^4/4!-x^6/6!+.....

Note-(Here ! is used for factorial of that number and ^ for to the power)


What I have tried is-:


class sincos
{
void main(double x,int n)
{
int i,j,k,f;
double sum=0.0;
x=Math.toRadians(x);
{
for(i=1,j=1;i<=n;i=i+2,j++)
{
f=1;
for(k=1;k<=i;k++)
{
f=f*i;
}

if(j%2==0)
sum=sum-(Math.pow(x,i)/f);
else
sum=sum+(Math.pow(x,i)/f);
}
System.out.println("sin"+Math.toDegrees(x)+"="+sum);
}

for(i=0,j=1;i<=n;i=i+2,j++)
{
f=1;
for(k=1;k<=i;k++)
{
f=f*i;
}

if(j%2==0)
sum=sum-(Math.pow(x,i)/f);
else
sum=sum+(Math.pow(x,i)/f);
}
System.out.println("cos"+Math.toDegrees(x)+"="+sum);
}}

My problem is that I am not understanding that whether the source code I wrote is correct or not as the output is coming something else .I checked the code many times but still can't understand where the problem is.
So can you check my source code and correct it according to the question.

-- modified 5-Dec-20 21:01pm.
AnswerRe: Using for loop create a bluej program for the question( https://1drv.ms/u/s! Ajrld_fzlfykhx8hc1sbkiufuc_p ) Pin
OriginalGriff26-Oct-20 21:05
mveOriginalGriff26-Oct-20 21:05 
QuestionRe: Using for loop create a bluej program for the question( https://1drv.ms/u/s! Ajrld_fzlfykhx8hc1sbkiufuc_p ) Pin
Richard MacCutchan26-Oct-20 22:51
mveRichard MacCutchan26-Oct-20 22:51 
QuestionRe: Using for loop create a bluej program for the question( https://1drv.ms/u/s! Ajrld_fzlfykhx8hc1sbkiufuc_p ) Pin
User 1494142127-Oct-20 5:16
MemberUser 1494142127-Oct-20 5:16 
AnswerRe: Using for loop create a bluej program for the question( https://1drv.ms/u/s! Ajrld_fzlfykhx8hc1sbkiufuc_p ) Pin
Richard MacCutchan27-Oct-20 5:24
mveRichard MacCutchan27-Oct-20 5:24 
GeneralRe: Using for loop create a bluej program for the question( https://1drv.ms/u/s! Ajrld_fzlfykhx8hc1sbkiufuc_p ) Pin
User 1494142127-Oct-20 5:39
MemberUser 1494142127-Oct-20 5:39 
GeneralRe: Using for loop create a bluej program for the question( https://1drv.ms/u/s! Ajrld_fzlfykhx8hc1sbkiufuc_p ) Pin
User 1494142127-Oct-20 5:38
MemberUser 1494142127-Oct-20 5:38 
GeneralRe: Using for loop create a bluej program for the question( https://1drv.ms/u/s! Ajrld_fzlfykhx8hc1sbkiufuc_p ) Pin
Richard MacCutchan27-Oct-20 5:42
mveRichard MacCutchan27-Oct-20 5:42 
GeneralRe: Using for loop create a bluej program for the question( https://1drv.ms/u/s! Ajrld_fzlfykhx8hc1sbkiufuc_p ) Pin
User 1494142127-Oct-20 5:46
MemberUser 1494142127-Oct-20 5:46 
GeneralRe: Using for loop create a bluej program for the question( https://1drv.ms/u/s! Ajrld_fzlfykhx8hc1sbkiufuc_p ) Pin
Richard MacCutchan27-Oct-20 5:56
mveRichard MacCutchan27-Oct-20 5:56 
GeneralRe: Using for loop create a bluej program for the question( https://1drv.ms/u/s! Ajrld_fzlfykhx8hc1sbkiufuc_p ) Pin
Richard MacCutchan27-Oct-20 7:10
mveRichard MacCutchan27-Oct-20 7:10 
AnswerRe: Write a program using for loop that computes sinx and cosx by using the following power series- sinx=x-x^3/3!+x^5/5!-x^7/7!+.... cosx=1-x^2/2!+x^4/4!-x^6/6!+..... Note-(Here ! is used for factorial of that number and ^ for "power of" Pin
Patrice T6-Nov-20 15:59
mvePatrice T6-Nov-20 15:59 
AnswerInterview Question locking for Ans Pin
sureshkct26-Oct-20 4:52
Membersureshkct26-Oct-20 4:52 
QuestionRe: Interview Question locking for Ans Pin
Richard MacCutchan26-Oct-20 5:34
mveRichard MacCutchan26-Oct-20 5:34 
GeneralRe: Interview Question locking for Ans Pin
Dave Kreskowiak27-Oct-20 6:54
mveDave Kreskowiak27-Oct-20 6:54 
QuestionJAVA IF ELSE STATEMENT (HELP ME) Pin
tomatomoa24-Oct-20 7:45
Membertomatomoa24-Oct-20 7:45 
AnswerRe: JAVA IF ELSE STATEMENT (HELP ME) Pin
Sandeep Mewara24-Oct-20 8:17
mveSandeep Mewara24-Oct-20 8:17 
GeneralRe: JAVA IF ELSE STATEMENT (HELP ME) Pin
tomatomoa3-Nov-20 2:18
Membertomatomoa3-Nov-20 2:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.