Answer the question
In order to leave comments, you need to log in
For loop-input from keyboard or how to do it?
Hello, can you help me solve equations Math.sqrt(x+1)?Math.sqrt(1-2*Math.sin(x)) in Java using a for loop
double x, dx, xg;
Scanner sc = new Scanner(System.in);
System.out.println("from: ");
if (sc.hasNextDouble())
x = sc.nextDouble();
else {
System.out.println("input error");
sc.close();
return;
}
System.out.println("to: ");
if (sc.hasNextDouble())
xg = sc.nextDouble();
else {
System.out.println("input error");
sc.close();
return;
}
System.out.println("step: ");
if (sc.hasNextDouble())
dx = sc.nextDouble();
else {
System.out.println("input error");
sc.close();
return;
}
sc.close();
System.out.println("x-------F");
for (;x<=xg;) {
if (x<-1 || 2*Math.sin(x)>0 ||
Math.abs(1-2*Math.sin(x))<0.0001)
System.out.println(x + " not defined");
else
System.out.println(x + " " +
Math.sqrt(1+x)/Math.sqrt(1-2*Math.sin(x)));
x=x+dx;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question