導航:首頁 > 編程語言 > java統計數據

java統計數據

發布時間:2022-12-31 23:57:40

java 怎麼對數據各欄位的值做統計分析

寫for循環來算,可以寫一個介面,返回一個數值,然後根據你的要求去實現它。統計哪個數就放哪個實現類。JAVA不像Python那麼多數學分析函數可用,當然也有第三方的數學計算包,看你找不找得到了。

❷ java統計每組實驗數據中的最大值,最小值,平均值。

importjava.math.BigDecimal;
importjava.text.DecimalFormat;
importjava.util.Scanner;

publicclassTest{

(Stringprompt){
Scannerscanner=newScanner(System.in);
System.out.print(prompt);
returnscanner.nextLine();
}

privatestaticvoidhandArray(Stringinput){
if(null==input||"".equals(input)){
System.out.println("輸入參數不能為空");
return;
}
DecimalFormatdf=newDecimalFormat("#.00");
String[]tempArray=input.split("");
Doublemin=null;
Doublemax=null;
BigDecimaltotal=newBigDecimal(0.0);
for(Stringtemp:tempArray){
if(min==null){
min=Double.parseDouble(temp);
}else{
if(min>Double.parseDouble(temp)){
min=Double.parseDouble(temp);
}
}
if(max==null){
max=Double.parseDouble(temp);
}else{
if(max<Double.parseDouble(temp)){
max=Double.parseDouble(temp);
}
}

total=total.add(newBigDecimal(Double.parseDouble(temp)));
}

BigDecimalave=total.divide(newBigDecimal(tempArray.length),2);

System.out.println(df.format(min)+""+df.format(max)+""+df.format(ave.doubleValue()));
}

publicstaticvoidmain(String[]args){
Integerrepeat=newInteger(1);

while(repeat>0){
Stringstr=readDataFromConsole("Pleaseinputrunningtime:");
repeat=Integer.parseInt(str);
if(repeat<=0||repeat>100){
System.out.println("");
}else{
String[]inputArrays=newString[repeat*2];
for(inti=0;i<repeat*2;i++){
Scannerscanner=newScanner(System.in);
inputArrays[i]=scanner.nextLine();
}
System.out.println("輸出");
for(Stringinput:inputArrays){
if(input.split("").length>1){
handArray(input);
}
}
repeat=0;
}
}
}

}

輸入輸出:

Pleaseinputrunningtime:2
3
369
5
1.91.83.445.66.7
輸出
3.009.006.00
1.806.703.89

❸ #java如何實現數據統計#用Java實現店鋪的數據統計,PV,UV等信息

1、在第三方網站中加入統計腳本;
2、當網站被訪問時候,腳本會發送當前瀏覽器的信息、訪問者的信息及當前頁面信息提交到統計的伺服器;
3、統計伺服器定期對提交上來的數據進行分析和匯總;

❹ Java如何進行資料庫里的數據統計

你這個跟java沒什麼關系,資料庫自己就能實現。
T-SQL這樣寫就可以了

select * into table2 from table1
where (time>3:00 and time<5:00) --這句是偽代碼,你把條件改對

如果要統計數據條數,另寫一條sql查。
如果table2已經建好,請先刪除。
-------------------------------------------------------
這還不簡單啊,把上面的內容組合一下。

select count(*) as count_num from table1 where (你的條件)
--這句得到數據條數了。
再加上這句
select no,time from table1 where (你的條件)
--這句得到所有符合條件的數據。

插入也可以用子查詢
--假設table2的id是自增的
insert into table2(no,time) values(
select no,time from table1 where(你的條件)
)

你在java里通過這些查詢已經得到你要的數據了,再處理下就行了。
也可以把所有的查詢都變成子查詢然後放到一個SQL語句裡面,不過好象沒必要。

❺ 用java統計資料庫的數據

private Connection conn=null;
private PreparedStatement ps=null;
private String DRIVER="com.microsoft.sqlserver.jdbc.SQLServerDriver";
private String STRCONN="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=merchandise";
private String USER="sa";
private String PASS="sasa";
/**
* 創建一個連接方法
*/
public Connection createConnection(){
try {
Class.forName(DRIVER);
conn=DriverManager.getConnection(STRCONN,USER,PASS);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
上面是連接 sql server 2005的方法 下面是要查的用法

總數:select count(*)from
表名男生人數:select count(*)from 表名 where
性別那一列的名字='男'女生的把上面改一下就行了

❻ Java 統計資料庫中符合條件的行數 怎麼做

有兩種方式
1.通過sql語句:
如select count(id) from tab where id<10;
這樣查出來的就是行數

2. 在java中
//sqlRst是ResultSet 對象的實例
int RowCount = sqlRst.getRow();//獲得當前行號

❼ java開發動態表單怎麼存儲數據和統計

java開發動態表單存儲數據和統計步驟是:
1、通過一個表定義的表(有點繞),描述一下表和數據欄位的信息。
2、通過數據描述,描述數據表的基本組成。
3、完成。

❽ java 中有沒有統計同一類型數據個數的函數

好像直接的方法統計個數沒有,需要你自己分割計數或者用正則表達式匹配來計算。

❾ Java關於數組統計數據

大個比方。第一個集合responses[]裡面放的是班級每人的分數,從0分到10分。 有人得1分 有人得2分 有人得3分。第二個集合,有連個作用:他的下標(就是0,1,2,3,4等等)代表的是分數,因為他聲明的時候int frequency[]=new int[11];所以這個集合的長度是11位,整好是0分~11分。 第一個循環,每當出現一次1分,就把第二個集合里的第1個值+1. 每當出現一個2分,就把第二個集合里的第2個值+1.。 到最後,第二個集合frequency里,放的信息就是:下標+下標所代表的分數出現的次數。 下標是0,就代表0分,frequency[0]就代表0分出現了幾次(即有幾個人是0分),同理下標是1,就代表1分,frequency[1]就代表1分出現了幾次(即有幾個人是1分)

❿ java怎樣將集合中的數值數據分區間統計個數:例如(0-1000)有幾個人數據,1000-2000有幾個數據

集合分組統計處理, 實現的方法很多,簡單的寫幾種方法供參考;(理解後,自行擴展完善)

方法一:(Java8流處理粗略版) 該版本存在的問題:有些區間沒有數據,就不列印顯示該區間

importjava.util.*;
importjava.util.stream.*;

publicclassNumberDemo{
publicstaticvoidmain(String[]args){

ArrayList<Integer>list=newArrayList<Integer>();
intnumbers=10;//集合里數字的個數
intspace=1000;//區間的間隔

//給集合里添加數字
Randomrd=newRandom();
for(inti=0;i<numbers;i++){
list.add(rd.nextInt(5000));//集合里每個數字的范圍是0~4999
}

funStream(list,space);
}

privatestaticvoidfunStream(ArrayList<Integer>list,intspace){
//使用流處理把數字分組
Map<String,List<Integer>>map=list.stream().collect(Collectors.groupingBy((num)->{
return"區間:["+num/space*space+","+(num/space+1)*space+")";//分組規則
}));
map.forEach((k,v)->{
System.out.println(k);
System.out.println(" "+v.size()+"個數據");
});
}
}

方法二:(Java8流處理詳細版) 就算有的區間是0個數據,照樣列印出來

importjava.util.*;
importjava.util.stream.*;

publicclassNumberDemo2{
publicstaticvoidmain(String[]args){
ArrayList<Integer>list=newArrayList<Integer>();
intnumbers=10;//集合里數字的個數
intspace=1000;//區間的間隔

//給集合里添加數字
Randomrd=newRandom();
for(inti=0;i<numbers;i++){
list.add(rd.nextInt(5000));//集合里每個數字的范圍是0~4999
}

funStream(list,space);
}

privatestaticvoidfunStream(ArrayList<Integer>list,intspace){
//使用流處理把數字分組
Map<Integer,List<Integer>>map=list.stream().collect(Collectors.groupingBy((num)->{
returnnum/space;//分組規則
}));

//獲取集合里的最大值
Optional<Integer>maxop=list.stream().collect(Collectors.maxBy(Integer::compareTo));
intmax=maxop.orElse(0);
//計算出區間的數量
intgroups=max%space==0?max/space:max/space+1;
//列印結果
for(inti=0;i<groups;i++){
System.out.println("區間:["+i*space+","+(i+1)*space+")");
System.out.println(" 有"+(map.get(i)==null?0:map.get(i).size())+"個數據");
//System.out.println(" "+map.get(i));//把數據列印出來
}
}
}

方法三:(比較傳統的方法)

importjava.util.*;

publicclassNumberDemo3{
publicstaticvoidmain(String[]args){
ArrayList<Integer>list=newArrayList<Integer>();
intnumbers=10;//集合里數字的個數
intspace=1000;//區間的間隔

//給集合里添加數字
Randomrd=newRandom();
for(inti=0;i<numbers;i++){
list.add(rd.nextInt(5000));//集合里每個數字的范圍是0~4999
}

fun(list,space);
}
privatestaticvoidfun(ArrayList<Integer>list,intspace){
Collections.sort(list);//排序
intmax=list.get(list.size()-1);//取得最大值
intgroups=max%space==0?max/space:max/space+1;//取得區間的數量
HashMap<Integer,ArrayList<Integer>>map=newHashMap<Integer,ArrayList<Integer>>();//存區間和該區間的數字
for(inti=0;i<groups;i++){
map.put(i,newArrayList<>());
}
//把元素添加到指定的區間
for(inti=0;i<list.size();i++){
map.get(list.get(i)/space).add(list.get(i));
}
//列印結果
for(inti=0;i<groups;i++){
System.out.println("區間:["+i*space+","+(i+1)*space+")");
System.out.println(" 有"+map.get(i).size()+"個數據");
//System.out.println(" "+map.get(i));//把數據列印出來
}
}
}

測試效果如下

區間:[0,1000)
有5個數據
區間:[1000,2000)
有0個數據
區間:[2000,3000)
有1個數據
區間:[3000,4000)
有2個數據
區間:[4000,5000)
有2個數據
閱讀全文

與java統計數據相關的資料

熱點內容
dvd光碟存儲漢子演算法 瀏覽:757
蘋果郵件無法連接伺服器地址 瀏覽:962
phpffmpeg轉碼 瀏覽:671
長沙好玩的解壓項目 瀏覽:142
專屬學情分析報告是什麼app 瀏覽:564
php工程部署 瀏覽:833
android全屏透明 瀏覽:736
阿里雲伺服器已開通怎麼辦 瀏覽:803
光遇為什麼登錄時伺服器已滿 瀏覽:302
PDF分析 瀏覽:484
h3c光纖全工半全工設置命令 瀏覽:143
公司法pdf下載 瀏覽:381
linuxmarkdown 瀏覽:350
華為手機怎麼多選文件夾 瀏覽:683
如何取消命令方塊指令 瀏覽:349
風翼app為什麼進不去了 瀏覽:778
im4java壓縮圖片 瀏覽:362
數據查詢網站源碼 瀏覽:150
伊克塞爾文檔怎麼進行加密 瀏覽:892
app轉賬是什麼 瀏覽:163