java控制台代码大全 java中的控制台是什么

求Java代码使用循环结构,通过Scanner类从控制台输入每个人的捐款金额,并累加每个人的捐款金额,计算捐款总数和捐款人数,如果捐款总数达到10万元,则计算平均每人捐款金额 。
下面是通过输入进行统计,实际过程中还能是通过数据库进行操作,或者表格收集数据进行导入关系数据库进行统计 。还可以通过接入微信或者支付宝小程序收款实时统计 。
已经有人给过随机数示例,这里给出前端输入的示例:
import java.util.Scanner;
public class CharityDonation {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int num = 0;// 捐款人数
int total = 0;// 募捐总数
int avg = 0;// 平均每人捐款金额
int donation;// 每个人的捐款金额
while (total100000num1000) {
System.out.print("请输入第" + (num + 1) + "个人的捐款金额:");
donation = scanner.nextInt();
total += donation;
num++;
}if (total = 100000) {
avg = total / num;
System.out.println("捐款总数已达到10万元,捐款人数为" + num + ",平均每人捐款金额为" + avg + "元 。");
} else {
System.out.println("征集慈善募捐失败 , 募捐总数未达到10万元 。");
}
scanner.close();
}
}
用java控制台实现万年历-要求打印当前年月日的日历表格,要求对当天的日期单独标示以下是用java swing编写的日历,很好用 , 在我所做的系统里就能够正常的使用
接下来 是具体代码:
package Demo;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.border.LineBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class DateChooser extends JPanel implements ActionListener,
ChangeListener {
/**
*
*/
private static final long serialVersionUID = 1L;
int startYear = 1980;
int lastYear = 2050;
int width = 270;
int height = 200;
Color backGroundColor = Color.gray;
Color palletTableColor = Color.white;
Color todayBackColor = Color.orange;
Color weekFontColor = Color.blue;
Color dateFontColor = Color.black;
Color weekendFontColor = Color.red;
Color controlLineColor = Color.pink;
Color controlTextColor = Color.white;
Color rbFontColor = Color.white;
Color rbBorderColor = Color.red;
Color rbButtonColor = Color.pink;
Color rbBtFontColor = Color.red;
JDialog dialog;
JSpinner yearSpin;
JSpinner monthSpin;
JSpinner hourSpin;
JSpinner minuteSpin;
JButton[][] daysButton = new JButton[6][7];
JFormattedTextField jFormattedTextField;
Calendar c = getCalendar();
DateChooser(JFormattedTextField jftf) {
jFormattedTextField = jftf;
setLayout(new BorderLayout());
setBorder(new LineBorder(backGroundColor, 2));
setBackground(backGroundColor);
JPanel topYearAndMonth = createYearAndMonthPanal();

推荐阅读