引用 | 编辑
totsi
2009-04-22 08:22 |
3楼
▲ ▼ |
Java我不会..不过用c++可以这样写
char *pcNum = NULL; int nNo = 0; scanf("%d", &nNo);//取得输入值 pcNum = new char[nNo];//allocate memory for ( int i = 0 ; i < nNo ; i++ ) { pcNum[0] = i+1;//放在阵列里面 printf("%s\n", pcNum);//印出来 } delete pcNum;//release memory pcNum = NULL; x0 |
引用 | 编辑
jim28791
2009-04-23 23:36 |
4楼
▲ |
不知你想要的是不是这样~~
复制程式 import java.io.*; class bn { public static void main(String args[]) throws IOException { BufferedReader buf; String str; int x,y=0; buf = new BufferedReader(new InputStreamReader(System.in)); System.out.print("请输入数字:"); str = buf.readLine(); x=Integer.parseInt(str); int tmn[]=new int[x]; for(int i=1;i<x;i++)if(test(i)==0) { tmn[y]=i; y++; } for(int i=0;i<tmn.length;i++)if(tmn[i]!=0)System.out.println(tmn[i]);else break; } public static int test(int n) { for(int i=2;i<=Math.sqrt(n);i++)if(n%i==0)return 1; return 0; } } java还不太熟~~~ 对于怎么让阵列需要时才加空间~ 这我不太会~~ 所以~这程式会占用许多多余的空间XD x0 |