我简单做了一下:我觉得这个题好像有问题 因为静态方法只能调用静态变量 所以首先把变量修改为静态变量 不知道是否符合楼主的意思 public class Test1 { static String a = "hk001"; public static void main(String[] args) { for (int i = 0; i < 10; i++) { // 这里就是我想没循环一次"hk001"就变为hk002,003m,,,,这样 if(i>=0 && i<9){ String temp = a.substring(0,4); System.out.println(temp+(i+1)); }else{ String temp = a.substring(0,3); System.out.println(temp+(i+1)); } } } }
static String a = "hk"; static String sFormat = "000"; public static void main(String[] args) {
static String a = "hk"; static String sFormat = "000"; public static void main(String[] args) { DecimalFormat format = new DecimalFormat(sFormat); for (int i = 0; i < 10; i++) { System.out.println(a+format.format((i+1))); } }
for (int i = 0; i < 10; i++) { System.out.printf("%s%03d%s", "hk", i, (i==9)?"\n":", ") }
public class Test3 { static String a="hk001"; public static void main(String[] args) { a=a.substring(0,4); int j=0; for(int i=0;i<10;i++){ j++; System.out.println(a+j); } }}
{ String a = "hk001";
public static void main(String[] args)
{
for(int i = 0 ;i < 10 ; i++)
{
//这里就是我想没循环一次"hk001"就变为hk002,003m,,,,这样 }
}
}
public class Test1 {
static String a = "hk001";
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
// 这里就是我想没循环一次"hk001"就变为hk002,003m,,,,这样
if(i>=0 && i<9){
String temp = a.substring(0,4);
System.out.println(temp+(i+1));
}else{
String temp = a.substring(0,3);
System.out.println(temp+(i+1));
}
}
}
}
static String sFormat = "000";
public static void main(String[] args) {
static String sFormat = "000";
public static void main(String[] args) {
DecimalFormat format = new DecimalFormat(sFormat);
for (int i = 0; i < 10; i++) {
System.out.println(a+format.format((i+1)));
}
}
System.out.printf("%s%03d%s", "hk", i, (i==9)?"\n":", ")
}
static String a="hk001";
public static void main(String[] args) {
a=a.substring(0,4);
int j=0;
for(int i=0;i<10;i++){
j++;
System.out.println(a+j);
} }}