循环取值 得到一组数,比如200个,需要按每5个分组,如:1~5为1组,6~10为2组,40个组,请问如何写呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 int[][5] result = new int[total / 5][5]; package untitled26;import java.io.*;public class Untitled1 { public Untitled1() { } public static void main(String[] args) throws Exception{ FileWriter fw = new FileWriter("c:/fc.txt");//生成的5个一组的文件放在c:\叫fc.txt BufferedWriter bw = new BufferedWriter(fw); int line=0; for(int j=0;j<40;j++){ bw.write("\r\n"); for(int i=0;i<5;i++) bw.write((line++)+"\r,"); }System.out.print("写入成功");bw.flush();bw.close();fw.close(); }} public class FormatOutput { public static void main (String args[]){ String str = ""; int[] intArray = new int[200]; for (int i=0; i<200; i++) intArray[i] = i; for (int i=0; i<200; i++){ if ((i%5 == 0)&&(i !=0)) str += "\n"; str += intArray [i] +" "; } System.out.print(str); }}0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 eclipse问题,高手请进~ 关于socket连接21端口 action请求页面 gridbaglayout组件总是居中 悬赏百分解决httpunit处理下拉框的问题(问题解决立即结贴) 很简单的问题,但不知道你会不会? 新手2个简单的问题,送60分 java中的这个错误提示是什么意思! java的主要应用问题 如何判断输入的一个数是不是整型?? JComboBox的内容怎么打出来了两次? 哪位有jview的教程呢。。。
public class Untitled1 {
public Untitled1() {
}
public static void main(String[] args) throws Exception{
FileWriter fw = new FileWriter("c:/fc.txt");//生成的5个一组的文件放在c:\叫fc.txt
BufferedWriter bw = new BufferedWriter(fw);
int line=0;
for(int j=0;j<40;j++){
bw.write("\r\n");
for(int i=0;i<5;i++)
bw.write((line++)+"\r,");
}
System.out.print("写入成功");
bw.flush();
bw.close();
fw.close(); }
}
public static void main (String args[]){
String str = "";
int[] intArray = new int[200];
for (int i=0; i<200; i++)
intArray[i] = i;
for (int i=0; i<200; i++){
if ((i%5 == 0)&&(i !=0))
str += "\n";
str += intArray [i] +" ";
}
System.out.print(str);
}
}
0 1 2 3 4
5 6 7 8 9
10 11 12 13 14
15 16 17 18 19
20 21 22 23 24
25 26 27 28 29
30 31 32 33 34
35 36 37 38 39
40 41 42 43 44
45 46 47 48 49
50 51 52 53 54
55 56 57 58 59
60 61 62 63 64
65 66 67 68 69
70 71 72 73 74
75 76 77 78 79
80 81 82 83 84
85 86 87 88 89
90 91 92 93 94
95 96 97 98 99
100 101 102 103 104
105 106 107 108 109
110 111 112 113 114
115 116 117 118 119
120 121 122 123 124
125 126 127 128 129
130 131 132 133 134
135 136 137 138 139
140 141 142 143 144
145 146 147 148 149
150 151 152 153 154
155 156 157 158 159
160 161 162 163 164
165 166 167 168 169
170 171 172 173 174
175 176 177 178 179
180 181 182 183 184
185 186 187 188 189
190 191 192 193 194
195 196 197 198 199