⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 melon1_ex.java

📁 刘艺编著的java教程的课本习题加例题代码 很有用哦!
💻 JAVA
字号:
class Melon
{float weight;
 private static float total_weight=0;
 private static int total_number=0;
 public Melon(float w)
  {weight=w;
   total_weight=total_weight+weight;
   total_number=total_number+1;
   }
 public void reduce()
 {total_weight=total_weight-weight;
  total_number=total_number-1;
   }
 public static float get_total_weight()
 { return total_weight;}
 public static int get_total_number()
 { return total_number;}
}
public class Melon1_ex
{public static void main(String args[])
 {
 // System.out.println("Total weight:  "+Melon.get_total_weight());
  
  Melon m1,m2;
  float t_weight;
  int t_number;
  m1=new Melon(10);
  m2=new Melon(12);
  t_weight=Melon.get_total_weight();
  t_number=Melon.get_total_number();
  System.out.println("Total weight:  "+t_weight);
  System.out.println("Total number:  "+t_number);
  m1.reduce();
  t_weight=Melon.get_total_weight();
  t_number=Melon.get_total_number();
  System.out.println("Total weight:  "+t_weight);
  System.out.println("Total number:  "+t_number);
  }
}
  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -