java入门编程经典例题,简单的初学者java 题目

1,简单的初学者java 题目(1.):public class shupublic static void main(String args[])int n=2; int i;int z;for(i=1;i<=10;i++)z=n*i;System.out.println("n*"+i+"="+z); }} }执行结果很正确 , 你自己换数字运行一下(2):public class temp public static void main(String arg[]) float fah;//华氏温度 float cel; //摄氏温度 fah=(float)80; cel=(fah-32)*5/9; System.out.println("today temp is " + cel +"C");}}这个程序也是验证的?。?
2,几道java 初学题第5题public class hen{ public static void main(String args[]){for(int i=0;i<=20;i++){for(int j=0;j<=33;j++){if((5*i+3*j+(100-i-j)/3==100)&&((100-i-j)%3==0)){System.out.println("母鸡:"+i);System.out.println("公鸡:"+j);int temp=100-i-j;System.out.println("小鸡:"+temp);System.out.println();}}} }}
3,JAVA基础编程题package com.qiu.swing.layoutDemo;import java.awt.Container;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.Box;import javax.swing.BoxLayout;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JRootPane;import javax.swing.JTextField;/** * * @author Qiu * */public class TextDemo extends JFrame final JButton button_show = new JButton("显示"); final JButton button_clear = new JButton("显示"); final JTextField text = new JTextField(); final Container con = this.getContentPane(); public TextDemo()this.setTitle("HelloWorld!"); this.setSize(300, 160); // 居中 this.setLocationRelativeTo(null); this.setUndecorated(true); // 去掉窗口的装饰 this.setResizable(false); this.getRootPane().setWindowDecorationStyle( JRootPane.INFORMATION_DIALOG);// 采用指定的窗口装饰风格 // 文字居中 text.setSize(100, 20); Box vbox = Box.createVerticalBox(); Box xbox0 = Box.createHorizontalBox(); xbox0.add(text); xbox0.add(button_show); xbox0.add(button_clear); vbox.add(xbox0); vbox.add(Box.createVerticalStrut(100)); con.setLayout(new BoxLayout(con, BoxLayout.X_AXIS)); con.add(vbox); button_show.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)text.setText("HelloWorld"); } }); button_clear.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)text.setText(""); } });} public static void main(String[] args)TextDemo home = new TextDemo(); home.setVisible(true); }}【java入门编程经典例题,简单的初学者java 题目】
4 , 几道JAVA初级题目高手帮忙做下谢谢第1题int sum = 0;for(int i = 1; i <= 10; i++)int jsum = 1;for(int j = 1; j <= i; j++)jsum *= j;}sum += jsum;}System.out.println(sum); 第2题int sum = 0;for(int i = 2; i < 50; i++)boolean flag = true;for(int j = 2; j < i; j++)if(i % j == 0)flag = false;break;}}if(flag)sum += i;}}System.out.println(sum);第3题Random r = new Random();int[] a = new int[20];for(int i = 0; i < a.length; i++)a[i] = r.nextInt(51) + 50;}int max = a[0], index = 0;for(int i = 1; i < a.length; i++)if(max < a[i])max = a[i];index = i;}}System.out.println("最大数为" + max + ", 产生时的序号为:" + index);第4题 import java.util.Random; import java.util.Arrays;public class Testpublic static void main(String[] args)int[] a = new int[10];Random r = new Random();for(int i = 0; i < a.length; i++)a[i] = r.nextInt(91) + 10;//10到100之间的随机数,包含100}Arrays.sort(a);String result = Arrays.toString(a);System.out.println(result);} }第5题// 长方形周长public static double fun1(double w, double h)return 2 * (w + h);}// 长方形面积public static double fun2(double w, double h)return w * h;}// 正方形周长public static double fun3(double s)return 4 * s;}// 正方形面积public static double fun4(double s)return s * s;}// 圆周长public static double fun5(double r)return 2 * Math.PI * r;}// 圆面积public static double fun6(double r)return Math.PI * r * r;}你不就是高手嘛…… 。自己做5,java基础题目很简单?。龈龇庾袄郋mployee , SalariedEmployee和HourlyEmployee继承Employee , 其中的getSalary(int month)方法覆盖原方法,后面的也一样 , 我只给出思路 , 代码自己写下吧,这个就是个敲代码的题public class TestEmployee { public static void main(String[] args) {// 在这里面可以测试 }}class Employee{ private String name; private int birthMonth; public Employee(String name,int birthMonth){this.name=name;this.birthMonth=birthMonth; } public String getName(){return name; } public double getSalary(int month){if (this.birthMonth==month) return 100;else return 0; }}class SalariedEmployee extends Employee{ private double salary; public SalariedEmployee(String name,int birthMonth,double salary){super(name,birthMonth);this.salary=salary; } public double getSalary(int month){return salary+super.getSalary(month); }}class HourlyEmployee extends Employee{ private double salaryPerHour; private int hours; public HourlyEmployee(String name, int birthMonth, double salaryPerHour, int hours) {super(name, birthMonth);this.salaryPerHour = salaryPerHour;this.hours = hours; } public double getSalary(int month){double result=0;if (hours>160) result=160*this.salaryPerHour+(hours-160)*this.salaryPerHour*1.5;else result=this.hours*this.salaryPerHour;return result+super.getSalary(month); }}class SalesEmployee extends Employee{ private double sales; private double rate; public SalesEmployee(String name, int birthMonth, double sales, double rate) {super(name, birthMonth);this.sales = sales;this.rate = rate; } public double getSalary(int month) {return this.sales*this.rate+super.getSalary(month); }}class BasePlusSalesEmployee extends SalesEmployee{ private double basedSalary; public BasePlusSalesEmployee(String name, int birthMonth, double sales, double rate, double basedSalary) {super(name, birthMonth, sales, rate);this.basedSalary = basedSalary; } public double getSalary(int month) {return this.basedSalary+super.getSalary(month); }} 做过相应的程序懒得再写明天找到了发你上面的那位真强

    推荐阅读