java入门编程题,几道java 初学题

1,几道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();}}} }}
2,最基础的JAVA题乱打`package test;public class Arr{ /*** @param args*/ public static void main(String[] args) {// TODO Auto-generated method stubint arr[]=new int[20];arr[0]=0;arr[1]=1;for(int i=2;i<20;i++){arr[i]=arr[i-1]+arr[i-2];}for(int i=0;i<20;i++){System.out.print(" "+arr[i]);} }}输出结果:0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181
3,java 初学者题目第一题: (输入每个值的时候都按回车,这个值中夹杂"stop"列入停止范围)具体程序如下: import java.util.Scanner; public class WhenStopOthers1 public static void main(String[] args) // TODO Auto-generated method stubScanner input = new Scanner(System.in);System.out.println("请输入:");String str = input.next();while (!str.equals("stop"))System.out.println("请继续输入,直到输入stop为止:");str = input.next();}System.out.println("输入结束.");} } /** *********************我是分隔线******************* **/第二题: (对已经赋值的一维数组进行逆序输出) 程序如下:public class BackOutpublic static void main(String[] args)String[] s =for(int i = s.length - 1; i &gt;= 0 ; i--) System.out.print(s[i]);if(i == 0) System.out.println();}}} }【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基础题目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); }} 做过相应的程序懒得再写明天找到了发你上面的那位真强很简单?。龈龇庾袄郋mployee,SalariedEmployee和HourlyEmployee继承Employee , 其中的getSalary(int month)方法覆盖原方法,后面的也一样,我只给出思路,代码自己写下吧,这个就是个敲代码的题

    推荐阅读