java統計
❶ java 統計
select webname,web_count from tbl limit 1,9 order by web_count
unoin all
select '其他' as webname, tmp.web_count from (select * from tbl limit 10,1 order by web_count) tmp
❷ java數據次數統計 求解
看代碼:
importjava.util.ArrayList;
importjava.util.Map;
importjava.util.Scanner;
importjava.util.TreeMap;
publicclassMain{
publicstaticvoidmain(String[]args)throwsException{
try(Scannerin=newScanner(System.in)){
intkey,value;
//TreeMap是可以根據鍵值進行自動排序的Map
//一個鍵可能對應多個值,我們使用ArrayList來保存這多個值
TreeMap<Integer,ArrayList<Integer>>map=newTreeMap<>();
while(true){
key=in.nextInt();
value=in.nextInt();
if(0==key&&0==value){//兩個都是0跳出循環
break;
}
if(null==map.get(key)){//當前key沒有對應的集合
ArrayList<Integer>values=newArrayList<>();
values.add(value);
map.put(key,values);
}else{
map.get(key).add(value);
}
}
for(Map.Entry<Integer,ArrayList<Integer>>entry:map.entrySet()){
System.out.printf("%d%d",entry.getKey(),entry.getValue().size());
for(Integerv:entry.getValue()){
System.out.printf("%d",v);
}
System.out.println();
}
}
}
}
運行:

❸ java數據統計怎麼做
你的問題還真是具體啊~~~~~~ 
不知道你問的是什麼東西,如果用容器的話vector、hashmap什麼的都可以
給你一個例子:
Vector<String> myVector = new Vector<String>();
myVector.add("example");
這就是最簡單的應用hashmap不過是多了個建值而已
有什麼不懂的可以hi我
❹ java中統計一個方法調用多少次
總體思路,定義一個靜態全局變數來統計方法執行次數,每進方法一次,統計次數加1
所有方法執行完成時,輸出統計次數就可以了。
示例代碼如下:
public class CountTest {
    public static int count1 = 0;
    public static int count2 = 0;
    public static void main(String[] args) {
        Random r = new Random();
        for (int i=0; i < 10; i++) {
            int num = r.nextInt();
            if (num > 0.5) {
                method1();
            } else {
                method2();
            }
        }
         
        System.out.println(count1 + " " + count2);
    }
     
    public static void method1() {
        count1++;
    }
     
    public static void method2() {
        count2++;
    }
}
❺ java如何統計網站訪問量
步驟一、建一個表,表名任意,這里取名為:visitorcounter,表的結構如下所示:
+-------+------------------+------+-----+------------+----------------+
| Field | Type             | Null | Key | Default    | Extra          |
+-------+------------------+------+-----+------------+----------------+
| id    | int(11) unsigned | NO   | PRI | NULL       | auto_increment |
| vdate | date             | NO   |     | 2000-01-01 |                |
| vnum  | int(11)          | NO   |     | 0          |                |
+-------+------------------+------+-----+------------+----------------+
步驟二、建立一個java類,名字也為:visitorcounter,類的內容如下:
package com.hdzx.pub;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Date;
public class VisitorCounter {
 private final static String TABLE_NAME = "visitorcounter";
 private static String today = null;
 private static long today_num = 0;
 private static long total_num = 0;
 //載入訪問量
 public static void loadNum(){
  if(total_num<1)
   loadTotalNum();
  if(today_num<1)
   loadToadyNum();
 }
 //載入今日訪問量
 private static void loadToadyNum() {
  // TODO Auto-generated method stub
  DBConnect db = null;
  ResultSet rs = null;
  if(today==null)
   today = getTodayDate();
  String sql = "select vnum from "+TABLE_NAME+" where vdate='"+today+"'";
  try {
   db = new DBConnect();
   rs = db.executeQuery(sql);
   if(rs.next()){
    today_num = rs.getLong("vnum");
   }
   else
   {    
    sql = "insert into "+TABLE_NAME+"(vdate,vnum) values('"+today+"',0)";
    db.executeUpdate(sql);
    today_num = 0;
   }
  } catch (Exception e) {
   // TODO: handle exception
   today_num = 0;
   System.out.println("com.hdzx.pub~VisitorCounter.incTotalCounter:獲得訪問人數");
  }
 }
 //載入總訪問量
 private static void loadTotalNum() {
  // TODO Auto-generated method stub
  // TODO Auto-generated method stub
  DBConnect db = null;
  ResultSet rs = null;
  if(today==null)
   today = getTodayDate();
  String sql = "select vnum from "+TABLE_NAME+" where id=1";
  try {
   db = new DBConnect();
   rs = db.executeQuery(sql);
   if(rs.next()){
    total_num = rs.getLong("vnum");
   }
   else
   {
    total_num = 0;
   }
  } catch (Exception e) {
   // TODO: handle exception
   total_num = 0;
   System.out.println("com.hdzx.pub~VisitorCounter.incTotalCounter:獲得訪問人數");
  }
 }
 //增加總的訪問量
 private static int incTotalCounter(){
  int k = 0;
  DBConnect db = null;
  loadNum(); 
  total_num = total_num+1;
  String sql = "update "+TABLE_NAME+" set vnum="+total_num+" where id=1";
  try {
   db = new DBConnect();
   k = db.executeUpdate(sql);
  } catch (Exception e) {
   // TODO: handle exception
   System.out.println("com.hdzx.pub~VisitorCounter.incTotalCounter:增加訪問人數");
  }
  return k;
 }
 //增加今日的訪問量
 public static int incTodayCounter(){
  int k  = 0;
  DBConnect db = null;
  String sql = null;
  loadNum();
  today_num += 1;
  sql = "update "+TABLE_NAME+" set vnum="+today_num+" where vdate='"+today+"'";
  try {
   db = new DBConnect();
   k = db.executeUpdate(sql);
   if(k > 0)
    incTotalCounter();
  } catch (Exception e) {
   // TODO: handle exception
   System.out.println("com.hdzx.pub~VisitorCounter.incTotalCounter:增加訪問人數");
  }
  return k;
 }
 //獲得今天的日期
 private static String getTodayDate(){
  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  return sdf.format(new Date());
 }
 ///獲得今日訪問量
 public static long getTodayNum(){
  loadNum();
  return today_num;
 }
 //獲得總的訪問量
 public static long getTotalNum(){
  loadNum();
  return total_num;
 } 
}
步驟三、經過以上的步驟後,在頁面中加入以下的代碼,就可以實現網站訪問量的統計工作:
if(session.isNew())
       {
            VisitorCounter.incTodayCounter();
       }
      %>
      今日訪問量:<%=VisitorCounter.getTodayNum() %><br/>
      總的訪問量: <%=VisitorCounter.getTotalNum() %>
❻ 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 實現報表統計
java本身沒有操作excel的工具,需要第三方的jar包,用jxl就可以,代碼入下。
jxl你上網路搜索後下載就可以,簡單易用,不懂追問。
public boolean exportExcel(HttpServletResponse response,List<cityinfo> list) 
    {   
try 
{ 
OutputStream os = response.getOutputStream();// 取得輸出流   
        response.reset();// 清空輸出流   
        response.setHeader("Content-disposition", "attachment; filename=fine.xls");// 設定輸出文件頭   
        response.setContentType("application/msexcel");// 定義輸出類型 
        
        WritableWorkbook wbook = Workbook.createWorkbook(os); // 建立excel文件   
        String tmptitle = "標題"; // 標題   
        WritableSheet wsheet = wbook.createSheet("詳細信息表", 0); // sheet名稱  
WritableSheet wsheet = wbook.createSheet("性別統計表", 1); // sheet名稱
WritableSheet wsheet = wbook.createSheet("證件類型統計表", 2); // sheet名稱
        
// 設置excel標題   
WritableFont wfont = new WritableFont(WritableFont.ARIAL, 16,WritableFont.BOLD, 
                       false,UnderlineStyle.NO_UNDERLINE,Colour.BLACK);   
WritableCellFormat wcfFC = new WritableCellFormat(wfont); 
wcfFC.setBackground(Colour.AQUA); 
wsheet.addCell(new Label(1, 0, tmptitle, wcfFC));   
wfont = new jxl.write.WritableFont(WritableFont.ARIAL, 14,WritableFont.BOLD, 
                   false, UnderlineStyle.NO_UNDERLINE,Colour.BLACK);   
wcfFC = new WritableCellFormat(wfont);  
// 開始生成主體內容                   
wsheet.addCell(new Label(0, 2, "具體內容"));   
for(int i=0;i<list.size();i++)   <br="">{   
    wsheet.addCell(new Label(0, i+3, "");   
    wsheet.addCell(new Label(1, i+3,""); 
}           
// 主體內容生成結束           
wbook.write(); // 寫入文件   
wbook.close();  
os.close(); // 關閉流
return true; 
} 
catch(Exception ex) 
{ 
ex.printStackTrace(); 
return false; 
} 
    }
❽ java中怎麼統計輸入的次數
總體思路,定義一個靜態全局變數來統計方法執行次數,每進方法一次,統計次數加1
所有方法執行完成時,輸出統計次數就可以了。
示例代碼如下:
public class CountTest {
    public static int count1 = 0;
    public static int count2 = 0;
    public static void main(String[] args) {
        Random r = new Random();
        for (int i=0; i < 10; i++) {
            int num = r.nextInt();
            if (num > 0.5) {
                method1();
            } else {
                method2();
            }
        }
         
        System.out.println(count1 + " " + count2);
    }
     
    public static void method1() {
❾ java統計行數 幫幫忙~~謝謝了
public class CodeCounter {
 
 static long normalLines = 0;
 static long commentLines = 0;
 static long whiteLines = 0;
 
 public static void main(String[] args) {
  File f = new File("D:\\share\\JavaProjects\\TankWar1.9.11\\src");
  File[] codeFiles = f.listFiles();
  for(File child : codeFiles){
   if(child.getName().matches(".*\\.java$")) {
    parse(child);
   }
  }
  
  System.out.println("java代碼:" + normalLines);
  System.out.println("注釋行:" + commentLines);
  System.out.println("空白行:" + whiteLines);
  
 }
 private static void parse(File f) {
  BufferedReader br = null;
  boolean comment = false;
  try {
   br = new BufferedReader(new FileReader(f));
   String line = "";
   while((line = br.readLine()) != null) {
    line = line.trim();
    if(line.matches("^[\\s&&[^\\n]]*$")) {
     whiteLines ++;
    } else if (line.startsWith("/*") && !line.endsWith("*/")) {
     commentLines ++;
     comment = true; 
    } else if (line.startsWith("/*") && line.endsWith("*/")) {
     commentLines ++;
    } else if (true == comment) {
     commentLines ++;
     if(line.endsWith("*/")) {
      comment = false;
     }
    } else if (line.startsWith("//")) {
     commentLines ++;
    } else {
     normalLines ++;
    }
   }
  } catch (FileNotFoundException e) {
   e.printStackTrace();
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   if(br != null) {
    try {
     br.close();
     br = null;
    } catch (IOException e) {
     e.printStackTrace();
    }
   }
  }
 }
}
❿ java中如何實現 統計時間
JAVA獲取當前系統時間System.currentTimeMillis(); 毫秒
