一个java小程序

一个java 小程序~

package wangaibo.test;

import java.util.Scanner;

public class Test {
public static void main(String[] args){
int size = 0;
int sum = 0;
int count = 0;
System.out.print("请输入接待顾客的人数:");
Scanner sc = new Scanner(System.in);
if(sc.hasNextInt()){
size = sc.nextInt();
}
System.out.println();
for(int i=1;i<=size;i++){
int r = 0;
do{
sum += Test.exec(sc);
System.out.print("是否还有商品:");
if(sc.hasNextInt()){
r = sc.nextInt();
}
System.out.println();
}while(r==1);
System.out.println("当前顾客消费总价为:"+sum);
count += sum;
sum = 0;
}
System.out.println("所有顾客消费总价为:"+count);
}

public static int exec(Scanner sc){
int tp = 0;
int ts = 0;
System.out.print("请输入商品单价:");
if(sc.hasNextInt()){
tp = sc.nextInt();
}
System.out.println();
System.out.print("请输入商品数量:");
if(sc.hasNextInt()){
ts = sc.nextInt();
}
System.out.println();
return tp*ts;
}
}

import java.util.Scanner;
public class calendar{
public static void main(String[] args)
{
int sum=0;int i,j;
Scanner in=new Scanner(System.in);
System.out.println("请输入年");
int year=in.nextInt();
System.out.println("请输入月");
int month=in.nextInt();
for(i=1900;i<year;i++)
{
if(i%4==0&&i%100!=0||i%400==0)
{
sum+=366;
}
else
{
sum+=365;
}
}
for(j=1;j<month;j++)
{
if(j==2)
{
if(i%4==0&&i%100!=0||i%400==0)
{
sum+=29;
}
else
{
sum+=28;
}
}
else
{
if(j==1||j==3||j==5||j==7||j==8||j==10||j==12)
{
sum+=31;
}
else
{
sum+=30;

}
}
}
sum+=1;
int weekday=sum%7;
System.out.println("日一二三四五六");
for(int k=1;k<=weekday;k++)
{
System.out.print("");
}
if(j==1||j==3||j==5||j==7||j==8||j==10||j==12)
{
for(int m=1;m<=31;m++)
{
if(sum%7==6){System.out.print(m+"
");}
else{System.out.print(m+"");}
sum++;

}
}
if(j==4||j==6||j==9||j==11)
{
for(int n=1;n<=30;n++)
{
if(sum%7==6){System.out.print(n+"
");}
else{System.out.print(n+"");}
sum++;

}
}
if(j==2)
{
if(i%4==0&&i%100!=0||i%400==0)
{
for(int n=1;n<=29;n++)
{
if(sum%7==6){System.out.print(n+"
");}
else{System.out.print(n+"");}
sum++;
}
}
else{for(int n=1;n<=28;n++)
{
if(sum%7==6){System.out.print(n+"
");}
else{System.out.print(n+"");}
sum++;
}
}
}
}
}

完整程序: 5分钟写完,给分,嘿嘿

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class FontTest implements ActionListener {
private JFrame frame;
private JComboBox jcb;
private JRadioButton jrb1,jrb2,jrb3;
private JPanel jp;
private JLabel text;
public FontTest(){
//容器
frame=new JFrame("字体测试");
frame.setSize(400, 300);
frame.setBackground(Color.GRAY);
//面板
jp=new JPanel();
jp.setPreferredSize(new Dimension(400,300));
frame.setContentPane(jp);
//默认字体
Font font=new Font("宋体", Font.PLAIN, 16);
//字大小
jcb=new JComboBox();
jcb.setToolTipText("选择字体大小");
jcb.addItem("16");
jcb.addItem("18");
jcb.addItem("20");
jcb.addActionListener(this);
jcb.setPreferredSize(new Dimension(300,30));
jp.add(jcb);
//字风格
jrb1=new JRadioButton("PLAIN:普通",true);
jrb2=new JRadioButton("BOLD:加粗",false);
jrb3=new JRadioButton("ITALIC:倾斜",false);
jrb1.setPreferredSize(new Dimension(300,25));
jrb2.setPreferredSize(new Dimension(300,25));
jrb3.setPreferredSize(new Dimension(300,25));
jrb1.addActionListener(this);
jrb2.addActionListener(this);
jrb3.addActionListener(this);
jp.add(jrb1);
jp.add(jrb2);
jp.add(jrb3);
//文本
text=new JLabel();
text.setPreferredSize(new Dimension(300,40));
text.setFont(font);
text.setText("这些文字用来实时显示字体大小和风格");
text.setForeground(Color.RED);
jp.add(text);
//设置可见、设置可退出
frame.setVisible(true);
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
}

public void actionPerformed(ActionEvent e) {
if(e.getSource() instanceof JComboBox){
int index= jcb.getSelectedIndex();
int fontSize=16;
int style=text.getFont().getStyle();
if(index==1){
fontSize=18;
}else
if(index==2){
fontSize=20;
}
Font font=new Font("宋体",style,fontSize);
this.text.setFont(font);
text.repaint();
}else
if(e.getSource() instanceof JRadioButton){
int style=Font.PLAIN;
int fontSize=text.getFont().getSize();
JRadioButton jr=(JRadioButton)e.getSource();
if(jr.equals(jrb1)){
jrb1.setSelected(true);
jrb2.setSelected(false);
jrb3.setSelected(false);
style=Font.PLAIN;
}else
if(jr.equals(jrb2)){
jrb2.setSelected(true);
jrb1.setSelected(false);
jrb3.setSelected(false);
style=Font.BOLD;
}else
if(jr.equals(jrb3)){
jrb3.setSelected(true);
jrb1.setSelected(false);
jrb2.setSelected(false);
style=Font.ITALIC;
}
Font font=new Font("宋体",style,fontSize);
this.text.setFont(font);
}
}

public static void main(String[] args) {
new FontTest();
}

}

java不是也有Css么??
font_size=4px

一个java小程序
答:完整程序: 5分钟写完,给分,嘿嘿 import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.*;public class FontTest implements ActionListener { private JFrame frame;private JComboBox jcb;private JRadioButton jrb1,jrb2,jrb3;private J...

一个JAVA小程序的问题
答:2.public String breed() { System.out.println(name+"随便给口吃的");} 实现接口的子类中重写出错了。你的方法要返回String类型的值而不是输出。将接口和子类中的方法的返回值String改为void。代码贴上:———test.java———interface withpet { public void breed();public void play();} ...

求写一个java小程序
答:import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import javax.swing.JOptionPane;/** * 复制文件或文件夹 * * zww */public class ...

写一个JAVA小程序。
答:package test;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import java.util.Scanner;public class TSceen {private static Integer getInt() {Integer i = null;Scanner scanner = new Scanner(System.in);System.out.println("请输入整数长度不多于5位");while (i...

求大大用java编写一个小程序
答:nextInt();}catch(InputMismatchException exp){ System.out.println("Error!Invalid value, program ends!");//类型出错,程序出错,停止哦 break;} if(inputValue >= 20 ){ System.out.println("Error! Invalid value, program ends!");//数字大于20,出错,程序停止额 break;} } } } ...

帮忙写一个简单的java小程序
答:import java.io.IOException;import java.util.ArrayList;import java.util.Iterator;public class Test { / param args / public static void main(String[] args) { // TODO Auto-generated method stub boolean flag = true;// 是否还输入 Student stu = null;ArrayList al = new ArrayList();...

用java编写一个小程序
答:import java.util.*;public class TestComparable { public static void main(String[] args) { List s = new ArrayList();s.add(new Name("wang","fei"));s.add(new Name("wang","hong"));s.add(new Name("yang","lin"));s.add(new Name("li","ju"));s.add(new Name("liu...

用Java写个小程序:创建银行账号类SavingAccount,利用静态变量存储年利率...
答:import java.util.Scanner;public class SavingAccount { public static double account = 3000;public static double rate = 0.03;public void update(double rate){ this.rate = rate;} //flag 用来计算年利息和月利息,flag等true计算月利息 public double calc(double account , double rate , ...

求助,一个java小程序,谢谢、、、
答:public class Student { private String name;public int age;public void setName(String name){ this.name=name;} public String getName(){ return name;} public Student(String name,int age){ this.name=name;this.age=age;} public void print(Student stu){ System.out.println("name is...

求帮忙写一个java的小程序。
答:import java.util.Scanner;import java.util.regex.Pattern;public class EasyTest { public static void main(String[] args) { int num=0;Scanner scan;System.out.println("请输入一个字符串");scan=new Scanner(System.in);String s1=scan.nextLine();System.out.println("请输入一个字符");S...

IT评价网,数码产品家用电器电子设备等点评来自于网友使用感受交流,不对其内容作任何保证

联系反馈
Copyright© IT评价网