importjava.util.HashMap;
importjava.util.LinkedList;
importjava" />

嫒美直播免费版app下载-嫒美直播永久免费版下载-嫒美直播最新下载安装

當(dāng)前位置:首頁 > 教育綜合 > 正文

this.count = count

用java編寫小程序,已知a、b、c 3個(gè)隊(duì)伍進(jìn)行足球比賽,勝利3記分,平局1分,輸0分

importjava.util.Collections;
importjava.util.HashMap;
importjava.util.LinkedList;
importjava.util.List;
importjava.util.Map;
publicclassTest{
publicstaticvoidmain(String[]args){
finalString[]str={"a-b1:1","a-c2:1","b-c0:1"};

finalMapmap=newHashMap();
for(Strings:str){
finalString[]temp=s.split("");
finalString[]names=temp[0].split("-");
finalString[]counts=temp[1].split(":");
for(inti=0;i<2;i++){
Stringname=names[i];
intcount=Integer.parseInt(counts[i]);
if(map.containsKey(name)){
map.put(name,map.get(name)+count);
}else{
map.put(name,count);
}
}
}

finalListteams=newLinkedList();
for(Stringname:map.keySet()){
teams.add(newTeam(name,map.get(name)));
}
Collections.sort(teams);
System.out.println("隊(duì)伍:分");
for(Teamt:teams){
System.out.println(t.getName()+":"+t.getCount());
}
}
}
classTeamimplementsComparable{
privateStringname;
privateintcount;
publicTeam(Stringname,intcount){
this.name=name;
this.count=count;
}
publicvoidaddCount(intcount){
this.count=this.count+count;
}
publicStringgetName(){
returnname;
}
publicintgetCount(){
returncount;
}
publicintcompareTo(Teamo){
returno.getCount()-this.count;
}
}

用Java語言的LinkesList和集合寫個(gè)能夠自己輸入存儲(chǔ)商品名稱,數(shù)量,單價(jià)并計(jì)算價(jià)格價(jià)格是

importjava.util.ArrayList;
importjava.util.Scanner;
publicclassProduce{
privateStringname;
privateintcount;
privateintprice;
publicProduce(){
super();
}
publicProduce(Stringname,intcount,intprice){
super();
this.name=name;
this.count=count;
this.price=price;
}
publicStringgetName(){
returnname;
}
publicvoidsetName(Stringname){
this.name=name;
}
publicintgetCount(){
returncount;
}
publicvoidsetCount(intcount){
this.count=count;
}
publicintgetPrice(){
returnprice;
}
publicvoidsetPrice(intprice){
this.price=price;
}
//輸入商品信息方法
publicstaticArrayListInput(){
Scannersc=newScanner(System.in);
ArrayListal=newArrayList();
Stringname;
intcount,price;
System.out.println("輸入商品名稱:");
name=sc.nextLine();
System.out.println("輸入商品數(shù)量:");
count=sc.nextInt();
System.out.println("輸入商品單價(jià):");
price=sc.nextInt();
al.add(newProduce(name,count,price));
System.out.println("添加商品成功");
returnal;
}
//查看
publicstaticvoidFind(Stringname,ArrayListal){
for(Producep:al){
if(name.equals(p.getName())){
System.out.println("你要查看的商品是:"+p.getName()+"數(shù)量是:"
+p.getCount()+"單價(jià)是:"+p.getPrice()+"總價(jià)是:"
+(p.getCount()*p.getPrice()));
}
}
}

//刪除某個(gè)商品
publicstaticvoidDel(Stringname,ArrayListal){
for(inti=0;i if(name.equals(al.get(i).getName())){
System.out.println("刪除商品["+al.get(i).getName()+"]成功");
al.remove(i);
break;
}
}
}
publicstaticvoidmain(String[]args){
ArrayListal=newArrayList();
al=Input();//添加
Scannersc=newScanner(System.in);
System.out.println("輸入要查看的商品名:");
Stringfname=sc.next();
Find(fname,al);
System.out.println("輸入要?jiǎng)h除的商品名:");
Stringdname=sc.next();
Del(dname,al);
}
}

java畫直方圖,餅圖的源碼分析

我更改了一點(diǎn),完善一點(diǎn)。希望你能理解 import javax.swing.*; import java.awt.*; public class Histogram extends JPanel { private int[] count;//方圖的數(shù)值 private int x = 50;//x坐標(biāo)為50 public Histogram(){ this.count = new int[]{0,0,0,0,0};//默認(rèn)count repaint(); } public Histogram(int[] count){ this.count = count;//傳入count repaint

c:foreach語句在JSP頁面獲取不到值,頁面只顯示EL表達(dá) 請(qǐng)高手幫忙解答一下,謝謝。

items="${cg}" 你把cg放到某個(gè)scope下。再在scope中讀出來。比如:pageContext.setAttribute("cg",cg); 然后:items="${pageScope.cg}"

VisualC# winform窗體應(yīng)用程序 語句加this有的怎么不加?

在Form1類內(nèi)部,所有的變量可以不加 this。默認(rèn)地,存取類內(nèi)部的變量時(shí),都是 this。因此可以省略。但也有例外的情況,如下代碼所示

pubicpartialForm1:Form
{
privateintcount=0;//內(nèi)部私有變量

publicForm1(){……}//構(gòu)造函數(shù)

publicvoidSomeMethod(intcount)
{
this.count=count;//這里必須加上this.特指類內(nèi)部那個(gè)count變量
//如果省略this將產(chǎn)生編譯錯(cuò)誤
//count=count<---錯(cuò)誤的寫法
}
}
展開全文閱讀