import java.io.*;
public class Alone13_4 {
int a;
void getsum(int a){
this.a=a;
a+=a;
System.out.println("总数为:"+a);
System.out.println("平均数为:"+a/3);
}
void set(){
this.a=0;
}
public static void main(String [] args){
Alone13_4 al=new Alone13_4();
int i=1;
outer: for( ;true; ){
int b=0;
System.out.print("第"+i+"个整数:");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
try{
String s=br.readLine();
if(s!=null){
System.out.println(s);
b=Integer.parseInt(s);
b+=b;
s=null;
i++;
}
else{
continue outer;
}
}catch(Exception e){}
if(i==4){
al.getsum(b);
i=1;
al.set();
}
}
}
}
//我想输入三个数字,它就会进行计算,然后再问我输入数字.一直问下去.
可以它的计算结果错了.帮忙看一下
public class Alone13_4 {
int a;
void getsum(int a){
this.a=a;
a+=a;
System.out.println("总数为:"+a);
System.out.println("平均数为:"+a/3);
}
void set(){
this.a=0;
}
public static void main(String [] args){
Alone13_4 al=new Alone13_4();
int i=1;
outer: for( ;true; ){
int b=0;
System.out.print("第"+i+"个整数:");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
try{
String s=br.readLine();
if(s!=null){
System.out.println(s);
b=Integer.parseInt(s);
b+=b;
s=null;
i++;
}
else{
continue outer;
}
}catch(Exception e){}
if(i==4){
al.getsum(b);
i=1;
al.set();
}
}
}
}
//我想输入三个数字,它就会进行计算,然后再问我输入数字.一直问下去.
可以它的计算结果错了.帮忙看一下
解决方案 »
- url中的中文问题
- 在ubuntu中用java调用shell脚本生成的PS格式文件不能打开
- 求助,运行不正确,怎么改?
- MVC模式的特点和Struts各个组件同MVC的对应关系是什么
- 讨论一下关于java的传值还是引用
- 问一个下拉框的问题?
- 怎样设置打开文件对话框的过滤器
- 连接sql2008失败。求助
- 怎样把int转化为String
- 在javamail-1.2中有javadocs和sundocs,在sundoc中有com.sun.mail.pop3等的介绍,为什么会分为javadocs和sundocs两个?他们各自的作用?(我不
- NetBeans窗体位置的设置
- Java能与驱动程序数据实现通信吗?
this.a=a;
a+=a;b=Integer.parseInt(s);
b+=b;写的有问题 错在B这里
this.a=a;
a+=a;
删掉
可能不是楼主想要的,
import java.io.*;public class Alone13_4 {
int sum = 0; void getSum(int sum, int count) {
this.sum += sum;// this.a=a; a+=a; error!
System.out.println("总数为:" + sum);// 所有数字和
System.out.println("平均数为:" + sum / (count * 3));// 所有数字的平均数
} public static void main(String[] args) {
Alone13_4 al = new Alone13_4();
int i = 1; // 输入序号
int count = 0; // 计算次数,每输三个数计算一次即count+1
int theSum = 0; // 每三个数字和
outer: for (; true;) {
int b = 0;
System.out.print("第" + i + "个整数:");
BufferedReader br = new BufferedReader(new InputStreamReader(
System.in));
try {
String s = br.readLine();
if (s != null) {
System.out.println(s);
b = Integer.parseInt(s);
theSum += b;// b+=b; error!
s = null;
i++;
} else {
continue outer;
}
} catch (Exception e) {
}
if (i == 4) {
count++;
al.getSum(theSum, count);//
i = 1;
}
} }
}
this.a=0;
}
为什么我这方法不能实现?
因为这方法实现不了,所有当第二回输入时,计算出错了.....
我这样改还是不行
void set(int a){
this.a=a;
}
调用方法,我有用al.set(0);