Click here to Skip to main content
15,792,115 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 6:16
User 1494142127-Oct-20 6: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 6:24
mveRichard MacCutchan27-Oct-20 6: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 6:39
User 1494142127-Oct-20 6: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 6:38
User 1494142127-Oct-20 6: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 6:42
mveRichard MacCutchan27-Oct-20 6: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 6:46
User 1494142127-Oct-20 6: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 6:56
mveRichard MacCutchan27-Oct-20 6: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 8:10
mveRichard MacCutchan27-Oct-20 8: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 16:59
mvePatrice T6-Nov-20 16:59 
AnswerInterview Question locking for Ans Pin
sureshkct26-Oct-20 5:52
sureshkct26-Oct-20 5:52 
QuestionRe: Interview Question locking for Ans Pin
Richard MacCutchan26-Oct-20 6:34
mveRichard MacCutchan26-Oct-20 6:34 
GeneralRe: Interview Question locking for Ans Pin
Dave Kreskowiak27-Oct-20 7:54
mveDave Kreskowiak27-Oct-20 7:54 
QuestionJAVA IF ELSE STATEMENT (HELP ME) Pin
tomatomoa24-Oct-20 8:45
tomatomoa24-Oct-20 8:45 
AnswerRe: JAVA IF ELSE STATEMENT (HELP ME) Pin
Sandeep Mewara24-Oct-20 9:17
mveSandeep Mewara24-Oct-20 9:17 
GeneralRe: JAVA IF ELSE STATEMENT (HELP ME) Pin
tomatomoa3-Nov-20 3:18
tomatomoa3-Nov-20 3:18 
GeneralRe: JAVA IF ELSE STATEMENT (HELP ME) Pin
Richard MacCutchan3-Nov-20 4:11
mveRichard MacCutchan3-Nov-20 4:11 
QuestionLooking for a node.js developer for advanced disk wiping software (Almost complete) Pin
fixapc22-Oct-20 6:45
fixapc22-Oct-20 6:45 
AnswerRe: Looking for a node.js developer for advanced disk wiping software (Almost complete) Pin
Richard MacCutchan22-Oct-20 7:09
mveRichard MacCutchan22-Oct-20 7:09 
QuestionLog4j2 Migration Pin
Member 1496731916-Oct-20 5:21
Member 1496731916-Oct-20 5:21 
AnswerRe: Log4j2 Migration Pin
Richard MacCutchan16-Oct-20 5:38
mveRichard MacCutchan16-Oct-20 5:38 
QuestionJackson ObjectMapper valueToTree method also write valueType and integral but no actual value Pin
Manish K. Agarwal12-Oct-20 0:02
Manish K. Agarwal12-Oct-20 0:02 
QuestionWhy can't we make a sign up with phone number in android studio project Pin
Member 145474583-Oct-20 3:46
Member 145474583-Oct-20 3:46 
Question2d java graphics Pin
Member 149532531-Oct-20 3:07
Member 149532531-Oct-20 3:07 
AnswerRe: 2d java graphics Pin
CHill601-Oct-20 3:09
mveCHill601-Oct-20 3:09 
AnswerRe: 2d java graphics Pin
Richard MacCutchan1-Oct-20 4:02
mveRichard MacCutchan1-Oct-20 4: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.