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

Java

 
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 
OK, I am feeling generous, so here is part of the answer:
Java
import java.io.*;
import java.util.*;

class Trig {
    static double factorial(int number) {
        // calculate the factorial of a number
        double product = number;
        while (--number > 0) {
            product *= number;
        }
        return product;
    }

    static double sine(int angle) {
        // calculate the sin of an angle (in degrees)
        double radians = (Math.PI * angle) / 180.0; // convert angle to radians
        double sum = radians; // the first element of the series 
        boolean minus = true; // indicates whether to add or subtract the next element
        for (int power = 3; ; power += 2) {
            double dividend = Math.pow(radians, power);
            double divisor = factorial(power);
            double quotient = dividend / divisor; // divide the power of the number by the factorial of the power
            if (minus) {
                sum -= quotient;
            }
            else {
                sum += quotient;
            }
            minus = !minus;
            if (power > 20) // break the loop at a convenient point
                break;
        }
        return sum;
    }
    public static void main(String[] argv) {
        System.out.printf("sin(90)  = %f\n", sine(90));
        System.out.printf("sin(180) = %f\n", sine(180));
        System.out.printf("sin(270) = %f\n", sine(270));
    }
}

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 
GeneralRe: JAVA IF ELSE STATEMENT (HELP ME) Pin
Richard MacCutchan3-Nov-20 3:11
mveRichard MacCutchan3-Nov-20 3:11 
QuestionLooking for a node.js developer for advanced disk wiping software (Almost complete) Pin
fixapc22-Oct-20 5:45
Memberfixapc22-Oct-20 5:45 
AnswerRe: Looking for a node.js developer for advanced disk wiping software (Almost complete) Pin
Richard MacCutchan22-Oct-20 6:09
mveRichard MacCutchan22-Oct-20 6:09 
QuestionLog4j2 Migration Pin
Member 1496731916-Oct-20 4:21
MemberMember 1496731916-Oct-20 4:21 
AnswerRe: Log4j2 Migration Pin
Richard MacCutchan16-Oct-20 4:38
mveRichard MacCutchan16-Oct-20 4:38 
QuestionJackson ObjectMapper valueToTree method also write valueType and integral but no actual value Pin
Manish K. Agarwal11-Oct-20 23:02
MemberManish K. Agarwal11-Oct-20 23:02 
QuestionWhy can't we make a sign up with phone number in android studio project Pin
Member 145474583-Oct-20 2:46
MemberMember 145474583-Oct-20 2:46 
Question2d java graphics Pin
Member 149532531-Oct-20 2:07
MemberMember 149532531-Oct-20 2:07 
AnswerRe: 2d java graphics Pin
CHill601-Oct-20 2:09
mveCHill601-Oct-20 2:09 
AnswerRe: 2d java graphics Pin
Richard MacCutchan1-Oct-20 3:02
mveRichard MacCutchan1-Oct-20 3:02 

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.