Topic: 帮忙检查一下我自己写的这个程序!! |
Print this page |
1.帮忙检查一下我自己写的这个程序!! | Copy to clipboard |
Posted by: wwhui Posted on: 2006-09-18 21:42 我自己写了一个方法用于动态接收数字. 编译没有错误,但是运行不了.请帮忙看一下.不声感激!! //method; public static int transform(int j)throws Exception {ByteArrayOutputStream bb=new ByteArrayOutputStream(); while(bb.size()!=j) bb.write(System.in.read()); int p=Integer.parseInt(bb.toString()); return p; } 完整程序如下: import java.io.*; import java.util.*; public class tomorrowdate {public static void main(String args[])throws Exception {int m=0,n=0,k=0; System.out.println("输入年(4):"); m=transform(4); System.out.println("输入月(2):"); n=transform(2); System.out.println("输入日(2):"); k=transform(2); System.out.println(m); System.out.println(n); System.out.println(k); } // public static int transform(int j)throws Exception {ByteArrayOutputStream bb=new ByteArrayOutputStream(); while(bb.size()!=j) bb.write(System.in.read()); int p=Integer.parseInt(bb.toString()); return p; } // } |
2.Re:帮忙检查一下我自己写的这个程序!! [Re: wwhui] | Copy to clipboard |
Posted by: Novo Posted on: 2006-09-19 09:39 wwhui wrote: 编译能通过只能证明语法没有错误.但并不代表逻辑上没有错误.这是不相干两回事. |
3.Re:帮忙检查一下我自己写的这个程序!! [Re: wwhui] | Copy to clipboard |
Posted by: lisliefor Posted on: 2006-09-19 11:15 Your program didn't run as same as you think ! when you input year and press "Enter" , it would do numberformate from string to int , at that moment , your month and day were "" , so it throw NumberFormateException . I try to do it : (缩略图,点击图片链接看原图) |
4.Re:帮忙检查一下我自己写的这个程序!! [Re: wwhui] | Copy to clipboard |
Posted by: JiafanZhou Posted on: 2006-09-19 19:21 代码里面请不要加中文阿。。 感觉好怪。 嘉帆 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |