هنا كود تحويل الرقم إلى نص
وهذا بعد طلب أحد الاخوة في العمل
واسف لان الكودد ير منظم لانه كان على عجلا من امره
واحببت أن أفيد هذا المنتدى
العد المدخل يجب الا يتعدى تسعة أرقام
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package covertnumbertostring;
/**
*
* @author ALI SHEADAD
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String digits[]={"Zero ","One ","Two ","Three ","Four ","Five ",
"Six ","Seven ","Eight ","Nine ","Ten ","Eleven ","Twelve ",
"Thirteen ","Fourteen ","Fifteen ","Sixteen ","Seventeen ",
"Eighteen ","Nineteen "};
String tens[]={"Twenty ","Thirty ","Forty ","Fifty ","Sixty ","Seventy ","Eighty ","Ninety "};
int n=120351801;//Enter Number
int[] num = new int[9];//this Comment of Number n
for(int i=8 ; i>=0 ; i--)
{
num=n%10;
n=n/10;
}
boolean a=(num[0]+num[1]+num[2] > 0);//if not conatin Million alrady False
boolean b=(num[3]+num[4]+num[5] > 0);//if not conatin Thousand alrady False
boolean c=(num[6]+num[7]+num[8] > 0);//if not conatin Hundred
System.out.println();
for(int k=0 ; k<=6 ; k+=3)
{
if(num[k] != 0)
System.out.print("Hundred ");
if(num[k+1] > 1)
System.out.print(tens[num[k+1] - 2]);
if(num[k+1] == 1)
System.out.print( digits[10 * num[k+1] + num[k+2]]);
if(num[k+1]!=1 && num[k+2]!= 0)
System.out.print( digits[num[k+2]]);
if(k==0 && a)
{
System.out.print("Million ");
if(b || c) System.out.print(",");
}
if(k==3 && b)
{
System.out.print("Thousand ");
if(c)System.out.print(",");
}
}
System.out.print("\n\n");
}
}وأنا جاهز للمناقشة

