资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

用java编写星空代码 用java编写星号

用JAVA编写一个程序,要求如下:

实现代码如下:

创新互联建站是专业的晋安网站建设公司,晋安接单;提供成都做网站、网站建设,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行晋安网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

Student类:

public class Student {

private String name;

private String sex;

private int age;

private double chinese;

private double math;

private double english;

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getSex() {

return sex;

}

public void setSex(String sex) {

this.sex = sex;

}

public int getAge() {

return age;

}

public void setAge(int age) {

this.age = age;

}

public double getChinese() {

return chinese;

}

public void setChinese(double chinese) {

this.chinese = chinese;

}

public double getMath() {

return math;

}

public void setMath(double math) {

this.math = math;

}

public double getEnglish() {

return english;

}

public void setEnglish(double english) {

this.english = english;

}

}

-----------------------------------------------------------------

StudentTest类:(测试类)

import java.util.Scanner;

public class StudentTest {

public static void main(String[] args) {

Student student = new Student();

Scanner sc = new Scanner(System.in);

System.out.println("请输入姓名:");

student.setName(sc.next());

System.out.println("请输入性别:");

student.setSex(sc.next());

System.out.println("请输入年龄:");

student.setAge(sc.nextInt());

System.out.println("请输入语文成绩、数学成绩、英语成绩:");

student.setChinese(sc.nextDouble());

student.setMath(sc.nextDouble());

student.setEnglish(sc.nextDouble());

Double count = student.getChinese()+ student.getMath()+student.getEnglish();

System.out.println("姓名:"+student.getName()+" 性别:"+student.getSex()+" 年龄:"+student.getAge());

System.out.println("总分:"+count+" 平均分:"+count/3);

}

}

运行结果为:

怎么用java写下面的代码?

按照题目要求编写的Circle类的Java程序如下(文件名Circle.java)

public class Circle{

private double radius;

Circle(){

radius=0;

}

Circle(double r){

radius=r;

}

double getRadius(){

return radius;

}

double getLength(){

return 2*Math.PI*radius;

}

double getArea(){

return Math.PI*radius*radius;

}

void disp(){

System.out.println("圆的半径为"+getRadius());

System.out.println("圆的周长为"+getLength());

System.out.println("圆的面积为"+getArea());

}

}

下面是Circle类的测试类Test(文件名Test.java 要运行需要和Circle.java放在同一包内)

public class Test{

public static void main(String[] args){

Circle c=new Circle(2.5);

c.disp();

}

}

电脑怎么用代码画红底五角星

下面是用 Java 语言画一个红底五角星的代码示例:

import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics;

import javax.swing.JFrame; import javax.swing.JPanel;

public class FivePointedStar {

public static void main(String[] args) {

JFrame frame = new JFrame("Five Pointed Star");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

FivePointedStarPanel panel = new FivePointedStarPanel();

frame.add(panel);

frame.pack();

frame.setVisible(true);

}

}

class FivePointedStarPanel extends JPanel {

public FivePointedStarPanel() {

setPreferredSize(new Dimension(300, 300));

setBackground(Color.WHITE);

}

@Override

public void paintComponent(Graphics g) {

super.paintComponent(g);

int xPoints[] = {150, 200, 250, 225, 175, 125, 100, 125};

int yPoints[] = {100, 50, 100, 150, 150, 100, 50, 100};

int nPoints = 8; g.setColor(Color.RED);

g.fillPolygon(xPoints, yPoints, nPoints); }

}

这段代码中,我们创建了一个 JFrame 窗口,并在窗口中添加了一个 JPanel 面板。在面板中,我们重写了 paintComponent 方法,使用 Graphics 类的 fillPolygon 方法画出了一个五角星。我们设置了五角星的颜色为红色,并设置了面板的背景色为白色。

运行这段代码后,将会弹出一个窗口,显示一个红底五角星。

希望这个示例能帮助你画出一个红底五角星。

如何用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();

}

}

}

作为整个宇宙,介子π0/π±的数量比值是多少?,有个相对值亦可以的

国际上公认的计算π的值得最好的方法,就是在一向一个边长为1的正方形区域里面随机的扔一些石子,用落在扇形里面的个数和总的个数的一个比例关系,就可以近似求解出π的值。

就类似这样,我们可以知道这个比值 = (π/4),故π = 4*rate(比值) 。

下面贴一下Java的实现代码:

public class RandomPI {

public static void main(String[] args) {

// TODO Auto-generated method stub

System.out.println(rand_pi(100000)); //改变参数值

}

public static double rand_pi(int n) {

望采纳!

用java编写下面图形。n行。对称星星图,n为奇数 * *** ***** *** *

像这种图形对称的由少变多再变少可以考虑绝对值控制。

打个比方:就像在一个数轴上,越接近中心则距离越短,然后过了中心后,就会离中心越来越远。代码如下,如果n是可输入的,你用IO输入流代替即可。

public static void main(String[] args){

int n = 5;//*号的行数

/*控制*号的数量,最小为1,最大为n,由绝对值计算出变化*/

int m = 1;

int space = (n + 1) / 2;//空格的最大值

int s = 1;//和上面同理

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

//控制空格输出

for(int j = 0; j Math.abs(space-s); j++){

System.out.print(" ");

}

s++;

//控制*号输出

for(int k = 0; k n - Math.abs(n - m); k++){

System.out.print("*");

}

m += 2;

System.out.println();

}

}


新闻名称:用java编写星空代码 用java编写星号
标题链接:http://cdkjz.cn/article/hhjhgs.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220