مرحبا يا شباب .. انا عندي اكمن سؤال JAVA يا ريت اتجاوبوني عليها ضروري :)
السؤال الأول:
كيف يمكن ان اعرف عدد خانات احد الارقام .. حيث لدي برنامج يجب ان يتأكد اذا كان عدد خانات الرقم المدخل 5 خانات:
import javax.swing.JOptionPane;
public class Palindrome
{
public static void main(String args[])
{
String number = JOptionPane.showInputDialog("Enter a five digits integer:");
int n1 = Integer.parseInt(number);
int mul = 10000;
int a,b,c,d,e;
while ( log(n1) / log(10) + 1 != 5)
{
number = JOptionPane.showInputDialog("Enter a five digits integer:");
n1 = Integer.parseInt(number);
}
a = n1 / mul; // FIRST DIGIT
n1 = n1 % mul;
mul = mul / 10;
b = n1 / mul; // SECOND DIGIT
n1 = n1 % mul;
mul = mul / 10;
c = n1 / mul; // THIRD DIGIT
n1 = n1 % mul;
mul = mul / 10;
d = n1 / mul;
n1 = n1 % mul; // FORTH DIGIT
mul = mul / 10;
e = n1 / mul; // FIFTH DIGIT
if (a == e && b == d)
JOptionPane.showMessageDialog(null,number + " Is a palindrome number");
else
JOptionPane.showMessageDialog(null,number + " Is not a plindrome number");
}
}يعني اذا شايفين ال while
يجب ان اضع كود يتأكد لي اذا كان عدد خانات العدد المدخل هو خمسة او لا
Question2:
How to I make a program that prints the factorials for the numbers from 1 to 5
1 = 1 = 1
2 = 2 * 1 =2
3 = 3 * 2 * 1 = 6
And like this....
Here where I'am:
public class Factorials
{
public static void main(String args[])
{
for (int counter = 1; counter <= 5; counter++)
{
}
}
}وشكرا جزيلا لكم جميعا