英文:
Replacing integers to string
问题
我正在尝试在这里打印一些字母,我对Java还很陌生,无法弄清楚在模式中哪里添加这些字母。
package prints;
public class Pattern {
public static void main(String[] args) {
int rows = 6;
int[] diff = {0,1,3,5,7,9,11};
int blank = 0;
int b = 0;
int temp;
for(int i = rows; i >= 1; --i){
blank = diff[b++];
if(blank == 0)
temp = i-1;
else
temp = i;
for(int j = 1; j <= i; j++){
System.out.print(" " + j + " ");
}
for(int s = 0; s < blank; s++){
System.out.print(" ");
}
for(int k = temp; k >= 1; --k){
System.out.print(" " + k + " ");
}
System.out.println();
}
}
}
这是代码。在切换语言时遇到了问题。
英文:
I am trying to print some alphabets here, I am new to java and can't figure out where to add the alphabets in pattern.
package prints;
public class Pattern {
public static void main(String[] args) {
int rows = 6;
int[] diff = {0,1,3,5,7,9,11};
int blank = 0;
int b = 0;
int temp;
for(int i = rows; i >= 1; --i){
blank = diff[b++];
if(blank == 0)
temp = i-1;
else
temp = i;
for(int j = 1; j <= i; j++){
System.out.print(" "+ j + " ");
}
for(int s = 0; s < blank; s++){
System.out.print(" ");
}
for(int k = temp; k >= 1; --k){
System.out.print(" " + k + " ");
}
System.out.println();
}
}
}
this is the code. trouble in switching languages.
答案1
得分: 1
整数是数字,不是字符。因此,它们无法被“转换”。
但是你可以尝试使用字符。例如:
char h = (char) 72;
然后打印结果:
String.valueOf(h);
英文:
Integers are numbers, not characters. Therefore, they cannot be "converted".
You could however try using a char. For example:
char h = (char) 72;
Then print the result:
String.valueOf(h);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论