打印字符问题

我是绿油油茁壮的韭菜 2009-10-16 06:39:37

public class Dome1 {
public static void main(String args[]){

char ch1='1';
char ch2='z';
int numberPerLine=10;
printChars(ch1,ch2,numberPerLine);
}
public static void printChars(char ch1,char ch2,int numberPerLine){
for(int i=(char)(ch1);i<=(char)(ch2);i++){
if(i%numberPerLine==0)
System.out.println((char)i);
else
System.out.print((char)i+" ");
}
}
}


请大家帮我看看问题出现在哪?
每行要打印10个
可是我中是打印出这样的结果

1 2
3 4 5 6 7 8 9 : ; <
= > ? @ A B C D E F
G H I J K L M N O P
Q R S T U V W X Y Z
[ \ ] ^ _ ` a b c d
e f g h i j k l m n
o p q r s t u v w x
y z

请大家帮我改改!
一定要用这个方法头的public static void printChars(char ch1,char ch2,int numberPerLine)
我每份给,不好意思吖!
...全文
57 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jungle0627 2009-10-16
  • 打赏
  • 举报
回复
不用客气,我也是刚学没多久
  • 打赏
  • 举报
回复
谢谢了,你的果然就可以了!
我之前没学c,又刚刚学java
不会啊!
再次感谢!
jungle0627 2009-10-16
  • 打赏
  • 举报
回复
把方法改下就行了
public static void printChars(char ch1,char ch2,int numberPerLine){
int j = 0;
for(int i= ch1;i<= ch2;i++){
j ++;
if(j%numberPerLine==0)
System.out.println((char)i);
else
System.out.print((char)i+" ");
}
}

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧