java程序设计实训心得(java程序设计)

导读 大家好,我是小典,我来为大家解答以上问题。java程序设计实训心得,java程序设计很多人还不知道,现在让我们一起来看看吧!/*Test.java*/p...

大家好,我是小典,我来为大家解答以上问题。java程序设计实训心得,java程序设计很多人还不知道,现在让我们一起来看看吧!

/*Test.java*/

public class Test {

public static void main(String[] args)

{

System.out.println("问题1:");

Quest01.func1();

System.out.println("问题2:");

Quest02.func1();

System.out.println("问题3:");

Quest03.func1();

System.out.println("问题4:");

Quest04.func1();

}

}

/*Quest01.java*/

public class Quest01 {

public static void func1()

{

int sum=0;

for(int i=1;i<=100;i++)

{

sum+=i;

}

System.out.println(sum);

}

}

/*Quest02.java*/

public class Quest02 {

static void func1()

{

String str="";

for(int i=1;i<=9;i++)

{

for(int j=1;j<=9;j++)

{

if(j<=i)

{

str+=i+"*"+j+"="+i*j+" ";

}

if(j==i)

{

str+=" ";

break;

}

}

}

System.out.println(str);

}

}

/*Quest03.java*/

import java.util.Scanner;

public class Quest03 {

public static void func1()

{

float[] score=new float[5];

float max=0,min=0,avg=0;

Scanner s=new Scanner(System.in);

for(int i=0;i{ System.out.println("please input score "+i+":"); score[i]=s.nextFloat(); } max=score[0]; min=score[0]; avg=0; for(int i=0;i { if(score[i]>max) max=score[i]; if(score[i] min=score[i]; avg+=score[i]; } avg=avg/score.length; System.out.println("max="+max+" "+"min="+min+" "+"avg="+avg); } } /*Quest04.java*/ public class Quest04 { static void func1() { Person p1=new Person(); Student s1=new Student(); Teacher t1=new Teacher(); p1.eat(); s1.getName(); t1.getAge(); s1.playGame(); } } class Person { String name; int age; void eat() { System.out.println("eat()"); } String getName() { System.out.println("getName():"+name); return name; } int getAge() { System.out.println("getAge():"+age); return age; } } class Student extends Person implements PlayGame { Student() { this.name="学生"; this.age=10; } public void playGame() { // TODO Auto-generated method stub System.out.println("playGame()"); } } class Teacher extends Person { Teacher() { this.name="老师"; this.age=40; } } interface PlayGame { void playGame(); }

本文到此讲解完毕了,希望对大家有帮助。

最新文章