prit prit.......
provova versionin 1. te kodit, ne plan te pare nuk ka asnje problem. dmth funksionet me vlerat e pergjithshme, si: sin(cos) 30, 45, 60, ecc jane ne rregull por kur shkruaj psh: tan 90( i cili nuk egziston) me jep nje vlere 1.6.........e vazhdon. tani une e modifikova kodin per 2 raste qe kapa une, :
per tan 90, dhe cotan 0, qe te afishohet ndonje nesazh gabimi!
por do te doja te beja te njejten gje edhe per shumfishat e tyre, meqe keto funksione jane te pakten gjysem periodike, per te mos thene me periode te plote.
po per nje gje habitem, si ka mundesi qe meqe metoda eshte e gatshme, te mos kete te paracaktuar ate bashkesin e famshme te percaktimit????
ja kodin e aktualizuar:
Kodi:
import java.lang.Math;
public class Trig
{
public static void main(String[] args)
{
// Catch exceptions if there are any ...
try
{
double angle;
boolean err;
/* get the second argument in "java Trig args[0] args[1]
which will be args[1] the trigonometric funct.
*/
String function = args[1];
err=false;
Double argDouble = new Double(args[0]); // Assign args[0] to a Double type object
angle = argDouble.doubleValue(); // tear the primitive double value out of that, could have been done in one step
angle = angle * ( Math.PI / 180 );
/* Get the function and calculate it. */
if (function.equals("cos") )
angle = Math.cos(angle);
else if (function.equals("sin"))
angle = Math.sin(angle);
else if (function.equals("tan")){
if(angle==90*( Math.PI / 180 )){
System.out.println("Nuk eshte i percaktuar");
err=true;
}
else angle = Math.tan(angle);
}
else if (function.equals("cotan")){
if(angle==0){
System.out.println("Nuk eshte i percaktuar");
err=true;
}
else angle = 1 / Math.cos(angle);
}
else
{
System.out.println("Enter a regular function: cos, sin, tan, cotan");
return;
}
if(!err)System.out.println(angle); //Print the angle
}
catch (NumberFormatException e)
{
System.out.println("The angle MUST be a number ");
}
catch (ArrayIndexOutOfBoundsException e)
{
System.out.println("There should be two arguments, an angle and a function");
}
} // finished with main
}
//mos duhet te perdor cikel ketu, qe sa here te gjeje vlere te njejte, te kete nderprerje me break;???
Krijoni Kontakt