this.count = count
- 教育综合
- 2023-12-09 12:59:49
用java编写小程序,已知a、b、c 3个队伍进行足球比赛,胜利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("队伍:分");
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和集合写个能够自己输入存储商品名称,数量,单价并计算价格价格是
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("输入商品数量:");
count=sc.nextInt();
System.out.println("输入商品单价:");
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()+"数量是:"
+p.getCount()+"单价是:"+p.getPrice()+"总价是:"
+(p.getCount()*p.getPrice()));
}
}
}
//删除某个商品
publicstaticvoidDel(Stringname,ArrayListal){
for(inti=0;iif(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("输入要删除的商品名:");
Stringdname=sc.next();
Del(dname,al);
}
}
java画直方图,饼图的源码分析
我更改了一点,完善一点。希望你能理解 import javax.swing.*; import java.awt.*; public class Histogram extends JPanel { private int[] count;//方图的数值 private int x = 50;//x坐标为50 public Histogram(){ this.count = new int[]{0,0,0,0,0};//默认count repaint(); } public Histogram(int[] count){ this.count = count;//传入count repaintc:foreach语句在JSP页面获取不到值,页面只显示EL表达 请高手帮忙解答一下,谢谢。
items="${cg}" 你把cg放到某个scope下。再在scope中读出来。比如:pageContext.setAttribute("cg",cg); 然后:items="${pageScope.cg}"VisualC# winform窗体应用程序 语句加this有的怎么不加?
在Form1类内部,所有的变量可以不加 this。默认地,存取类内部的变量时,都是 this。因此可以省略。但也有例外的情况,如下代码所示
pubicpartialForm1:Form
{
privateintcount=0;//内部私有变量
publicForm1(){……}//构造函数
publicvoidSomeMethod(intcount)
{
this.count=count;//这里必须加上this.特指类内部那个count变量
//如果省略this将产生编译错误
//count=count<---错误的写法
}
}
展开全文阅读
上一篇
几一直加6等于2022
下一篇
返回列表