java中 将数字转换成字符

编写一个程序,打印ASCII字符表冲'!'到‘~’的字符。每行打印10个字符。
下面是我写的代码

//import java.util.Scanner;
public class welcome {
public static void main(String[] args){
// Scanner input=new Scanner(System.in);
int count=0;
for(int i=33;i<=126;i++)
{
char c=(char)i;
{
System.out.print(i+" ");
count++;
if(count%10==0)
System.out.println();
}
}
}
}
强制转换不行啊
该怎么弄啊
菜鸟 刚开始学习 才把那本书看到循环那一章 所以 不要用太深的东西
摆脱各位大神了

方法一:直接强制转换。如:String str= (String)123;
方法二:直接通过空字符串+数字的形式转换为字符串(前后都可以用)。如:String str= ""+123;
方法三:直接通过包装类来实现。如:String str = String.valueOf(1231);
温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-01-25
//import java.util.Scanner;
public class welcome {
public static void main(String[] args) {
// Scanner input=new Scanner(System.in);
int count = 0;
for (int i = 33; i <= 126; i++) {
char c = (char) i;//i强制转换成char类型之后为什么不使用?
{
// System.out.print(i + " ");//写错了 是c不是i,i是int类型的当然直接就输出数字了
System.out.print(c + " ");
count++;
if (count % 10 == 0)
System.out.println();
}
}
}
}

第2个回答  2014-01-25
i+" "会把‘i’转换成字符串的,而“++”只适用于数字类型的,所以会报错
第3个回答  推荐于2017-10-13
public class welcome {
public static void main(String[] args){
// Scanner input=new Scanner(System.in);
int count=1;
for(int i=33;i<=126;i++)
{
char c=(char)i;
System.out.print(c+"\t");
count++;
if(count%10==0)
System.out.println();
}
}
}本回答被提问者和网友采纳
第4个回答  2014-01-25
public static void main(String[] args){
// Scanner input=new Scanner(System.in);
int count=0;
for(int i=33;i<=126;i++)
{
char c=(char)i;
{
System.out.print(c+" ");
count++;
if(count%10==0)
System.out.println();
}
}
}
相似回答