Click here to Skip to main content
15,909,835 members
Home / Discussions / Java
   

Java

 
QuestionI'm a beginner and I'm only a month into Java. I struggle with a massive subject, is this a usual thing for begginers? It took me a long time to only understand this code. Pin
Denys Lysenko22-Nov-20 4:09
Denys Lysenko22-Nov-20 4:09 
AnswerRe: I'm a beginner and I'm only a month into Java. I struggle with a massive subject, is this a usual thing for begginers? It took me a long time to only understand this code. Pin
Richard MacCutchan22-Nov-20 4:32
mveRichard MacCutchan22-Nov-20 4:32 
GeneralRe: I'm a beginner and I'm only a month into Java. I struggle with a massive subject, is this a usual thing for begginers? It took me a long time to only understand this code. Pin
Denys Lysenko23-Nov-20 22:38
Denys Lysenko23-Nov-20 22:38 
GeneralRe: I'm a beginner and I'm only a month into Java. I struggle with a massive subject, is this a usual thing for begginers? It took me a long time to only understand this code. Pin
Richard MacCutchan23-Nov-20 22:47
mveRichard MacCutchan23-Nov-20 22:47 
Questionplease help Pin
Member 1499400615-Nov-20 22:33
Member 1499400615-Nov-20 22:33 
AnswerRe: please help Pin
Richard Deeming16-Nov-20 0:22
mveRichard Deeming16-Nov-20 0:22 
AnswerRe: please help Pin
Richard MacCutchan16-Nov-20 0:44
mveRichard MacCutchan16-Nov-20 0:44 
Questionjava applet wach Pin
Member 1499400615-Nov-20 22:31
Member 1499400615-Nov-20 22:31 
AnswerRe: java applet wach Pin
OriginalGriff15-Nov-20 22:32
mveOriginalGriff15-Nov-20 22:32 
QuestionNeed A Project To Show Employers? Ideas? Pin
CoderBryGuy4-Nov-20 7:13
CoderBryGuy4-Nov-20 7:13 
AnswerRe: Need A Project To Show Employers? Ideas? Pin
Richard MacCutchan4-Nov-20 21:41
mveRichard MacCutchan4-Nov-20 21:41 
GeneralRe: Need A Project To Show Employers? Ideas? Pin
Gerry Schmitz5-Nov-20 2:56
mveGerry Schmitz5-Nov-20 2:56 
GeneralRe: Need A Project To Show Employers? Ideas? Pin
Richard MacCutchan5-Nov-20 3:27
mveRichard MacCutchan5-Nov-20 3:27 
QuestionRealm EJB in Wildfly Pin
Andy_Bell31-Oct-20 0:55
Andy_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
Andy_Bell31-Oct-20 9:01 
GeneralRe: Realm EJB in Wildfly Pin
Andy_Bell11-Nov-20 23:46
Andy_Bell11-Nov-20 23:46 
Questionanyone know how a program would be written out for this Pin
Member 1497788728-Oct-20 9:53
Member 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 
GeneralMessage Closed Pin
28-Oct-20 10:11
Member 1497788728-Oct-20 10:11 
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
User 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
User 1494142127-Oct-20 5:16 

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.