Application程序的源文件和Java Applet程序的源文件有什么区别 (从下面两个来说他俩的区别)

Application程序的源文件和Java Applet程序的源文件有什么区别 (从下面两个来说他俩的区别),第1张

public class HeeloApp

{ public static void main (String args [ ])

{ system.out.println ( "Wlcome to Java World!" )}

}

是Application 程序,编译后按dos程序执行,没有颜色

package chapter1

import java.applet.Applet

import java.awt.*

public class HelloPkg extends Applet

{ public void paint (graphics g)

{

g.srtColor (color.red) //有颜色

g.drawString ( "Using package!", 40,50)//有位置

}

}

是Applet 程序,编译后需嵌入网页执行,有颜色。有位置

public class Js {

public int number = 20

public Js() {

}

public Js(int number) {

this.number = number

}

public double result() {

double result = 0

double temp = 1

for (int i = 1i <= numberi++) {

temp *= i

result += (1 / temp)

}

return result

}

// Js.java,计算1+1/2!+1/3!+1/4!+…的前20项的和

public static void main(String[] args) {

System.out.println(new Js(2).result())

System.out.println(new Js(5).result())

System.out.println(new Js(20).result())

}

}

2.int[] biggest(int a, int b, int c)

{

int order[]=new int[3]

if(a<=b)

{

if(b<=c)

{

order[0]=a

order[1]=b

order[2]=c

}

else

{

order[2]=b

if(a<=c)

{

order[0]=a

order[1]=c

}

else

{

order[0]=c

order[1]=a

}

}

}

else

{

if(a<=c)

order[0]=b

order[1]=a

order[2]=c

}

else

{

order[2]=a

if(b<=c)

{

order[0]=b

order[1]=c

}

else

{

order[0]=c

order[1]=b

{

}

return order

}

3.//没考虑平闰年

void printday(int x)

{

switch(x)

case 1:System.out.println("Jan has 31 days")break

case 2:System.out.println("Feb has 28 days")break

case 3:System.out.println("Mar has 31 days")break

case 4:System.out.println("Apr has 30 days")break

case 5:System.out.println("May has 31 days")break

case 6:System.out.println("Jun has 30 days")break

case 7:System.out.println("Jul has 31 days")break

case 8:System.out.println("Aug has 31 days")break

case 9:System.out.println("Sep has 30 days")break

case 10::System.out.println("Oct has 31 days")break

case 11:System.out.println("Nov has 30 days")break

case 12:System.out.println("Dec has 31 days")break

default: System.out.println("illegal input.")break

}

4

void array(int[] a)

{

int i, sum=0

double mean=0

for(i=0i<10i++)

{

sum+=a[i]

}

mean=sum/10.0

System.out.println("sum is "+sum+",mean is "+mean)

}

5

class Person

{

String name

int age

public Person(String name, int age)

{

this.name=name

this.age=age

}

void sayHello()

{

System.out.println("I am "+name+", and I am "+age+" years old, glad to meet you!")

}

}

class Student extends Person

{

String schoolname

String schoolno

public Student(String name, int age,String schoolname, String schoolno)

{

super(name,age)

this.schoolname=schoolname

this.schoolno=schoolno

}

public String toString()

{

String str=new String()

str=str.concat(this.name+"\t")

str=str.concat(this.age+"\t")

str=str.concat(schoolname+"\t")

str=str.concat(schoolid+"\t")

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12205794.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-21
下一篇 2023-05-21

发表评论

登录后才能评论

评论列表(0条)

保存