java代码写五星红旗,五星红旗编程

请问一个使用fillPolygon()画国旗上的五角星的算法

给你一个五星红旗的applet,用applet查看器就可以看。其它的你自己来吧

创新互联公司主要从事做网站、网站制作、网页设计、企业做网站、公司建网站等业务。立足成都服务马山,10余年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18982081108

import java.awt.*;

import java.applet.*;

public class HongQi extends Applet{

int r1=30; //外接大圆半径

int r0=(int)(r1*Math.cos(72*Math.PI/180)); //内圆半径

// 以下是大五角星坐标

int[] xrr={

(int)0, (int)(r0*Math.cos(54*Math.PI/180)),

(int)(r1*Math.sin(72*Math.PI/180)), (int)(r0*Math.cos(18*Math.PI/180)),

(int)(r1*Math.cos(54*Math.PI/180)), (int)0,

(int)((-r1)*Math.cos(54*Math.PI/180)),(int)((-r0)*Math.cos(18*Math.PI/180)),

(int)((-r1)*Math.sin(72*Math.PI/180)),(int)((-r0)*Math.cos(54*Math.PI/180))

};

int[] yrr={

(int)-r1, (int)(-r0*Math.sin(54*Math.PI/180)),

(int)(-r1*Math.cos(72*Math.PI/180)), (int)((r0)*Math.sin(18*Math.PI/180)),

(int)((r1)*(Math.sin(54*Math.PI/180))), (int)(r0),

(int)((r1)*(Math.sin(54*Math.PI/180))), (int)((r0)*Math.sin(18*Math.PI/180)),

(int)(-r1*Math.cos(72*Math.PI/180)), (int)(-r0*Math.sin(54*Math.PI/180)),

};

int[] xrr0=new int[10]; //小五角星坐标

int[] yrr0=new int[10];

public void init(){

for (int i = 0; i xrr.length; i++) { //计算大五角星坐标平移

xrr[i]+=50;

yrr[i]+=60;

}

for (int i = 0; i xrr0.length; i++) { //计算小五角星坐标平移

xrr0[i]=xrr[i]/3;

xrr0[i]+=80;

yrr0[i]=yrr[i]/3;

yrr0[i]+=17;

}

}

public void paint(Graphics g){

g.setColor(Color.RED);

g.fillRect(0,0,300,200);

g.setColor(Color.YELLOW);

g.fillPolygon(xrr,yrr,10);

g.fillPolygon(xrr0,yrr0,10);

g.copyArea(88,25,20,20,15,18);

g.copyArea(88,25,20,20,15,38);

g.copyArea(88,25,20,20,0,58);

}

}

5! 用java编写代码怎么写

用于你只是求5的阶乘,所以没必要弄得那么麻烦,不用对被阶乘数进行判断。当然可以更加复杂一点。

public class Demo{

public static void main(String[] args){

int a = 5;

int result = 1;

for(int i = 1;i = a; i ++){

result *= a;

}

System.out.println("5!的结果是: " + result);

}

}

如何用java写这段代码?

import java.security.InvalidKeyException;import java.security.NoSuchAlgorithmException;import javax.crypto.BadPaddingException;import javax.crypto.Cipher;import javax.crypto.IllegalBlockSizeException;import javax.crypto.KeyGenerator;import javax.crypto.NoSuchPaddingException;import javax.crypto.SecretKey;public class JEncrytion{

public static void main(String[] argv) {

try{ KeyGenerator keygenerator = KeyGenerator.getInstance("DES"); SecretKey myDesKey = keygenerator.generateKey();

Cipher desCipher; // Create the cipher

desCipher = Cipher.getInstance("DES/ECB/PKCS5Padding");

// Initialize the cipher for encryption

desCipher.init(Cipher.ENCRYPT_MODE, myDesKey); //sensitive information

byte[] text = "No body can see me".getBytes();

System.out.println("Text [Byte Format] : " + text);

System.out.println("Text : " + new String(text));

// Encrypt the text

byte[] textEncrypted = desCipher.doFinal(text);

System.out.println("Text Encryted : " + textEncrypted);

// Initialize the same cipher for decryption

desCipher.init(Cipher.DECRYPT_MODE, myDesKey); // Decrypt the text

byte[] textDecrypted = desCipher.doFinal(textEncrypted);

System.out.println("Text Decryted : " + new String(textDecrypted));

}catch(NoSuchAlgorithmException e){

e.printStackTrace();

}catch(NoSuchPaddingException e){

e.printStackTrace();

}catch(InvalidKeyException e){

e.printStackTrace();

}catch(IllegalBlockSizeException e){

e.printStackTrace();

}catch(BadPaddingException e){

e.printStackTrace();

}

}

}

Java编程,填写下面的代码

class NoLowerLetterException extends Exception {

public NoLowerLetterException(String msg) {

super(msg);

}

}

class NoDigitException extends Exception {

public NoDigitException(String msg) {

super(msg);

}

}

class People {

void printLetter(char c) {

if (c = 'a' c = 'z') {

System.out.println(c);

} else {

try {

throw new NoLowerLetterException(String.valueOf(c));

} catch (NoLowerLetterException e) {

e.printStackTrace();

}

}

}

void printDigit(char c) {

if (c = '0' c = '9') {

System.out.println(c);

} else {

try {

throw new NoDigitException(String.valueOf(c));

} catch (NoDigitException e) {

e.printStackTrace();

}

}

}

}

public class ExceptionExample {

public static void main(String args[]) {

People people = new People();

for (int i = 0; i 128; i++) {

// 【代码5】

// //将i转换为char类型,执行people.printLetter()方法,如果出现异常则捕获,并输出异常的错误信息!

people.printLetter((char) i);

}

for (int i = 0; i 128; i++) {

// 【代码6】 //将i转换为char类型,执行people. printDigit

// ()方法,如果出现异常则捕获,并输出异常的错误信息!

people.printDigit((char) i);

}

}

}

怎样用java编国旗

/**

* @(#)ChinaFlag.java

* ChinaFlag Applet application

* @黑色珊瑚

* @version 1.00 08/05/12

*/

import java.awt.*;

public class ChinaFlag extends Frame {

public static void main(String[] args) {

ChinaFlag cf=new ChinaFlag();

cf.setVisible(true);

}

public ChinaFlag() {

setBounds(100,100,400,300);

setBackground(Color.RED);

}

public void paint(Graphics g) {

drawStar(g,70,100,40);

drawStar(g,140,60,12);

drawStar(g,155,86,12);

drawStar(g,155,113,12);

drawStar(g,140,140,12);

}

private void drawStar(Graphics g,int x,int y,int width) {

double[] xb={0,

0.2245139882897926f, // sin18 * tan36

1.0514622242382672f, // 1 / cos18

0.3632712640026804f, // (sin18 * cos36) * sin72

0.5877852522924731f,0, // sin36 , 0

-0.5877852522924731f, // -sin36

-0.3632712640026804f, // -(sin18 * cos36) * sin72

-1.0514622242382672f, // -1 / cos18

-0.2245139882897926f}; // -sin18 * tan36

double[] yb={-1,

-0.3090169943749474f,

-0.3090169943749474f,

0.1180339887498948f, //

0.8090169943749474f,

0.3819660112501051f,

0.8090169943749474f,

0.1180339887498948f, //

-0.3090169943749474f,

-0.3090169943749474f};

g.setColor(Color.YELLOW);

int[] x1=new int[10];

int[] y1=new int[10];

for (int i=0; i10; i++) {

x1[i]=(int)(xb[i]*width+x);

y1[i]=(int)(yb[i]*width+y);

}

g.fillPolygon(x1,y1,10);

}

}

用java写程序,求教

求采纳,代码:

import java.util.Scanner;

public class main {

public static void main(String[] arg) { 

//

int NumF=0;

//负数个数 

int NumZ=0;

//正数个数

double sum=0;

//数字总和 

System.out.println("输入数字:"); 

Scanner in=new Scanner(System.in); 

String st=in.nextLine();//获得输入的内容

//循环遍历数组 

for(String a:st.split(" ")/*使用split分割字符串*/) { 

int b = 0; 

try {

b=Integer.valueOf(a);//使用Integer.valueOf();将字符串转化为数值

}catch (Exception e) { 

System.out.println("发生错误,可能输入了错误的数"); 

e.printStackTrace(); 

//判断数字正负 

if(b0) {

//如果是负数

NumF++;

//

sum=sum+b;

}else if (b0){

//如果是正数

NumZ++; 

sum=sum+b; 

}else if(b==0) { 

//如果为0就结束程序

System.out.println(NumZ); 

System.out.println(NumF);

System.out.println((double)sum/(NumF+NumZ));

}

}


网站标题:java代码写五星红旗,五星红旗编程
链接地址:http://myzitong.com/article/hcjpoi.html