资讯

精准传达 • 有效沟通

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

java写入代码 java代码的格式

如何用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写下面的代码?

按照题目要求编写的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代码?

只要自己的电脑安装了jdk环境,任何地方都可以进行java代码的编写的,记事本也可以。


文章名称:java写入代码 java代码的格式
文章路径:http://cdkjz.cn/article/dogiipi.html
多年建站经验

多一份参考,总有益处

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

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

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