欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

關(guān)于人員信息統(tǒng)計的java代碼 java統(tǒng)計在線人數(shù)

JAVA如何統(tǒng)計人數(shù)(接著下面的程序?qū)?

在類中聲明一個靜態(tài)變量如下 :

讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價值的長期合作伙伴,公司提供的服務(wù)項目有:域名申請網(wǎng)站空間、營銷軟件、網(wǎng)站建設(shè)、義烏網(wǎng)站維護、網(wǎng)站推廣。

static int num=0 ,每次類初始化將num 加一。

靜態(tài)變量為所有類共享,num的大小即為創(chuàng)建的student對象的數(shù)目

程序稍微改動如下:

class student {

String name;

static int num =0;

String id;

float ywscore;

float sxscore;

float sumscore;

float avgscore;

student(String name,String id,float ywscore,float sxscore){

this.name=name;

this.id=id;

this.ywscore=ywscore;

this.sxscore=sxscore;

num ++;

}

float sum(){

sumscore=sxscore+ywscore;

return sumscore;

}

float avg(){

avgscore=(sxscore+ywscore)/2;

return avgscore;

}

int getNum()

{

return num;

}

void showinfo(){

System.out.println("name: "+name);

System.out.println("id: "+id);

System.out.println("mathscore: "+sxscore);

System.out.println("langue: "+ywscore);

System.out.println("avg: "+avg());

System.out.println("sum: "+sum());

}

};

JAVA編程:輸入5個學(xué)生的信息(包含學(xué)號、姓名、3科成績),統(tǒng)計

能直接運行的:

import java.io.FileNotFoundException;

import java.io.IOException;

import java.io.Serializable;

import java.util.ArrayList;

import java.io.*;

import javax.naming.BinaryRefAddr;

public class Student implements Serializable{//Serializable是申明這個類可以被序列化

/**

* @param args

*/

public static void main(String[] args) {

ArrayList Student ss=new ArrayListStudent();

for(int i=0;i5;i++)//初始化5個學(xué)生

{

Student s=new Student(i,"學(xué)生"+i);

s.chenese_score=i+50;

s.english_score=i+75;

s.math_score=i+80;

ss.add(s);

}

try {

FileOutputStream fos=new FileOutputStream("d:/STUDENT.DAT");

try {

ObjectOutputStream oos=new ObjectOutputStream(fos);

for(int i=0;iss.size();i++)//初始化5個學(xué)生

{

Student s=ss.get(i);

oos.writeObject(s);//將學(xué)生遍歷出來寫入文件中

}

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

//從文件中讀取一個學(xué)生出來出來

try {

FileInputStream fis=new FileInputStream("d:/STUDENT.DAT");

try {

ObjectInputStream ois=new ObjectInputStream(fis);

try {

Student s=(Student)ois.readObject();

System.out.println("學(xué)生名為 "+s.name+"的總分為:"+s.getAll_score());

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

public int id;

public String name;

public int chenese_score;

public int math_score;

public int english_score;

public int all_score;

public Student(int id, String name) {

this.id = id;

this.name = name;

}

public int getAll_score()//獲取總成績

{

return this.chenese_score+this.english_score+this.math_score;

}

}

java編程統(tǒng)計總?cè)藬?shù)

classstudent{Stringname;Stringid;floatywscore;floatsxscore;floatsumscore;floatavgscore;student(Stringname,Stringid,floatywscore,floatsxscore){this.name=name;this.id=id;th...

class student {

String name;

String id;

float ywscore;

float sxscore;

float sumscore;

float avgscore;

student(String name,String id,float ywscore,float sxscore){

this.name=name;

this.id=id;

this.ywscore=ywscore;

this.sxscore=sxscore;

}

float sum(){

sumscore=sxscore+ywscore;

return sumscore;

}

float avg(){

avgscore=(sxscore+ywscore)/2;

return avgscore;

}

void showinfo(){

System.out.println("name: "+name);

System.out.println("id: "+id);

System.out.println("mathscore: "+sxscore);

System.out.println("langue: "+ywscore);

System.out.println("avg: "+avg());

System.out.println("sum: "+sum());

}

};

public class text {

public static void main(String [] args){

student s=new student("McGrady","01",90,99);

s.showinfo();

}

}創(chuàng)建多個STUDENT對象 統(tǒng)計student的個數(shù)!

JAVA創(chuàng)建5個雇員對象,設(shè)計程序找出五個雇員對象中年齡最大的員工,并將該員工的信息輸出到控制臺的代碼。

class Employee {//雇員類

int age;

//所有信息

}

class Test{

List list = new ArrayList();

//聲明創(chuàng)建五個對象

//比如Employee a = new Employee();

//......a.age = 30;

list.add(a);

//五個對象都加入List集合中

//然后遍歷取出,比較年齡

for(int i=0;ilist.size;i++)

{

//取出年齡最大的對象 e

}

//輸出e的所有信息

System.out.println(e.age + "其他信息");

}

利用java代碼,編寫JDBC連接數(shù)據(jù)庫新增員工信息的步驟. 員工信息表:t_emp(id int?

第一步:新建數(shù)據(jù)庫

連接的是本地localhost,新建一個新的數(shù)據(jù)庫名是jdbctest

然后建表t_emp

不會的話可通過執(zhí)行下方的sql語句建表

CREATE TABLE `t_emp` (

`id` int(11) NOT NULL AUTO_INCREMENT,

`name` varchar(255) DEFAULT NULL,

`salary` double DEFAULT NULL,

PRIMARY KEY (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

第二步:新建java項目

新建完以后添加mysql驅(qū)動的jar包,jar包自己下載

在項目上右鍵鼠標(biāo)屬性,然后

添加jar包,我這里已經(jīng)加載過了

第三步:編寫代碼

package com.gf;

import java.sql.DriverManager;

import java.sql.SQLException;

import com.mysql.jdbc.Connection;

import com.mysql.jdbc.Statement;

public class Test {

public static void main(String[] args) throws Exception {

int flag=0;

//1.加載驅(qū)動

Class.forName("com.mysql.jdbc.Driver");

//2.獲取連接

Connection conn=(Connection) DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/jdbctest?user=rootpassword=123456useUnicode=truecharacterEncoding=UTF-8");

//3.創(chuàng)建statement

Statement sm=(Statement) conn.createStatement();

//4.執(zhí)行sql語句

flag=sm.executeUpdate("insert into t_emp(name,salary) values('菲菲',34.9)");

if(flag!=0) {

System.out.println("員工信息增加成功");

}else {

System.out.println("添加失敗");

}

}

}

注意點:

---------------------------------------------------------------------------------

DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/jdbctest?user=rootpassword=123456useUnicode=truecharacterEncoding=UTF-8");

這里需要修改自己本機的連接信息,不然會出現(xiàn)連接失敗

最后的執(zhí)行結(jié)果

編寫java程序,輸入學(xué)生的人數(shù),然后逐個輸入每個學(xué)生的姓名和成績。統(tǒng)計成績的降序輸出學(xué)生的姓名。

import java.util.*;

class score

{

public static void main(String[]args)

{

//int [][] score=new int[3][4];

int score;

int sum=0;

int avg;

Scanner sc = new Scanner(System.in);

for(int i=0;i3;i++)//這句話有意思,我們?nèi)绻ザx了一個數(shù)值,如3那么就不需要寫這個int [][] score=new int[3][4];那如果吧3給去掉呢,那么就這樣寫for(int i=0;iscore.length;i++)

{

sum=0;

System.out.println("請輸入第"+(i+1)+"個班級的成績:");

for(int j=0;j4;j++)//如3那么就不需要寫這個int [][] score=new int[3][4];那如果吧3給去掉呢,那么就這樣寫for(int i=0;iscore[i].length;i++)

{

System.out.println("第"+(j+1)+"個學(xué)員的成績:");

score=sc.nextInt();//直到打印為4為止。這就是score=sc.nextInt();的用法。

sum=sum+score;

}

avg=sum/4;

System.out.println("第"+(i+1)+"個班級的平均分:"+avg+"分");

}

}

}

for 循環(huán) 當(dāng)內(nèi)層循環(huán)結(jié)束后,我們在去執(zhí)行外層循環(huán)。

打完收工。

看看 這個思路.

本文標(biāo)題:關(guān)于人員信息統(tǒng)計的java代碼 java統(tǒng)計在線人數(shù)
URL標(biāo)題:http://chinadenli.net/article32/hgdpsc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、品牌網(wǎng)站設(shè)計網(wǎng)站收錄、App設(shè)計商城網(wǎng)站、App開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)