21 Ekim 2016 Cuma

Java Cos Sin Tan ve Cot hesaplama

Bu bölümümüzde kullanıcının girmiş olduğu derecenin cos sin tan ve cot değerlerini bulup ekrana yazdıracağız.
Kullanıcıdan almış olduğumuz derece negatif bir değer olmamalı bu yüzden while döngüsü ile kullanıcının geçerli bir derece girmesini sağlayacağız.Kullanıcının girmiş olduğu dereceyi Math sınıfı ile sin cos tan değerlerini bulacağız. Math sınıfında cot değerini bulan bir komut yok. Ama cot=1/tan ile kolayca cot değerini ekrana yazdırabiliriz.

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dersler;
import java.util.Scanner;

public class Dersler {

    public static void main(String[] args)  {
    Scanner giris=new Scanner(System.in);
    int derece;
    double sin,cos,tan,cot;
    System.out.println("Verilen derecenin cos sin tan ve cot değerlerini bulma");
    System.out.println("Lütfen dereceyi giriniz:");
    derece=giris.nextInt();
    while(derece<0){
    System.out.println("Lütfen (0 veya 0 dan büyük) dereceyi giriniz:");
    derece=giris.nextInt();
    }
   
    sin=Math.sin(derece);
    cos=Math.cos(derece);
    tan=Math.tan(derece);
    cot=1/tan;
    System.out.println("Sonuç:");
    System.out.println("Sin("+derece+")="+sin);
    System.out.println("Cos("+derece+")="+cos);
    System.out.println("Tan("+derece+")="+tan);
    System.out.println("Cot("+derece+")="+cot);
    }
    }
   
Program Çıktısı:


1 yorum:

  1. kardeş Math.sin(x) olayında x değeri radyan cinsindendir. Ayrıca Sin(30) un 0.5 olduğunu bilmeyen bir sen kalmışsın dünyada.
    Biraz matematik çalış zira kodlar matematiğin dile dökülmüş halidir.

    YanıtlaSil