السلام عليكم
عندي برنامج سويته ووقف عند نقطة احترت فيها
وأبي مساعدتكم بليز !
import java.util.Scanner ;
public class Q1 {
public static void main (String args[]) {
double x , y ;
double square ;
double sqrt ;
int n ;
Scanner input = new Scanner (System.in);
System.out.println ("Choose what you want to compute: \n1.sprt\n2.square");
n = input.nextInt();
if (n==1) {
System.out.print ("Type a positive number: ");
x = input.nextDouble ();
if (x>=0){
y = Math.sqrt(x);
System.out.printf ("The square root of %.4f is %.4f",x,y);
}
}
else if (n==2){
System.out.print ("Type a positive number: ");
x = input.nextDouble ();
for ( int i=0 ; 0<=9999 ; i++)
{
if (x>0) {
y = x*x;
}
else {
System.out.print ("Type a positive number: ");
x = input.nextDouble ();
}
y = x*x;
System.out.printf ("The square of %.4f is %.4f",x,y);
}
}
else
System.out.println ("Invalid choice!");
}
}تحديداً داخل هال "If"
else if (n==2){
System.out.print ("Type a positive number: ");
x = input.nextDouble ();
for ( int i=0 ; 0<=9999 ; i++)
{
if (x>0) {
y = x*x;
}
else {
System.out.print ("Type a positive number: ");
x = input.nextDouble ();
}
y = x*x;
System.out.printf ("The square of %.4f is %.4f",x,y);
}
}ابي البرنامج يخلي المستخدم يدخل أرقام بالسالب .. ويطلب منه قيمه جديدة .. إلى ان يدخل قيمة موجبة .. فـ يشتغل عليها البرنامج ويطلع output
help !