1 问题
在日常生活中,对于数据的处理,为了使数据更加直观,我们可以使用柱状图,饼图,折线图等来呈现,同时也可以对数据直接进行一些处理,那怎样用java来处理这类问题呢?
2 方法
代码清单 1
import java.util.Scanner; public class Test00 { public static void main(String[] args) { System.out.println("请输入数字:"); Scanner sc = new Scanner(System.in); char x = sc.next().charAt(0); //求和 int a = 10, b = 2, c = 6; int d = a + b + c; System.out.println(d); //求平均数 float e = d / 3; System.out.println(e); //求极差 if (a != 0) { System.out.println(); } else if (b != 0) { System.out.println(); } else if (c != 0) { System.out.println("可以计算"); } int f = a - b; System.out.println("极差是:" + f); //求中位数 //中位数是中间两个的平均值(偶数) //中位数是中间的数(奇数) int i;i=7; if (i % 2 == 0) { System.out.println("是偶数"); } else if (i % 2 != 0) { System.out.println("是奇数"); } System.out.println("中位数是:"+b); } } |
3 结语
针对如何使用java来处理数据的问题,提出上述方式来分析数据的平均数,中位数等等来实现处理数据的方法,通过亲自实验,证明该方法是有效的,本文的方法并不完全,还有更多来分析处理数据的方式的方法,同时,在编程上仍有考虑不周的地方,未来可以继续研究更加简洁方便的代码进行处理。