资讯

精准传达 • 有效沟通

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

用java写的代码,java写的代码怎么运行

使用java编写代码如下要求

NewPhone类

成都创新互联是网站建设专家,致力于互联网品牌建设与网络营销,专业领域包括成都网站建设、网站建设、电商网站制作开发、微信小程序开发、微信营销、系统平台开发,与其他网站设计及系统开发公司不同,我们的整合解决方案结合了恒基网络品牌建设经验和互联网整合营销的理念,并将策略和执行紧密结合,且不断评估并优化我们的方案,为客户提供全方位的互联网品牌整合方案!

package com.baidu.question;

public class NewPhone extends Phone {

private boolean mute = true;

@Override

public void call() {

if(mute){

super.call();

}else{

System.out.println("语音已关闭");

}

}

//这里是直接设置

public void setMute(boolean mute){

this.mute=mute;

}

//担心你的题目是要求两种方法,写的第二种,下面两个方法负责开关

public void openMute(){

this.mute=true;

/*

* 也可以这样写

* setMute(true);

* 下边的方法一样

* */

}

public void closeMute(){

this.mute = false;

}

}

Phone类

package com.baidu.question;

public class Phone {

public void call(){

System.out.println("打电话");

}

}

测试类

package com.baidu.question;

public class PhoneTest {

public static void main(String[] args) {

Phone phone = new Phone();

phone.call();

NewPhone newPhone = new NewPhone();

newPhone.call();

newPhone.setMute(false);

newPhone.call();

newPhone.openMute();

newPhone.call();

newPhone.closeMute();

newPhone.call();

}

}

测试结果

打电话

打电话

语音已关闭

打电话

语音已关闭

给段最简单的java代码 让我新手看一下

最简单的java代码肯定就是这个了,如下:

public class MyFirstApp

{

public static void main(String[] args)

{

System.out.print("Hello world");

}

}

“hello world”就是应该是所有学java的新手看的第一个代码了。如果是零基础的新手朋友们可以来我们的java实验班试听,有免费的试听课程帮助学习java必备基础知识,有助教老师为零基础的人提供个人学习方案,学习完成后有考评团进行专业测试,帮助测评学员是否适合继续学习java,15天内免费帮助来报名体验实验班的新手快速入门java,更好的学习java!

java写的代码

package com.ailk.client;

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.FileReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.io.OutputStreamWriter;

import java.io.Reader;

public class FileTest {

public static void main(String[] args) {

// TODO Auto-generated method stub

String filePath = "d:/text1.txt";

readFile(filePath,99);

}

public static void readFile(String fileName, int grede){

File file = new File(fileName);

BufferedReader reader = null;

BufferedWriter bw = null;       

try {

System.out.println("以行为单位读取文件内容,一次读一整行:");

reader = new BufferedReader(new FileReader(file));

bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File("d:/test2.txt")), "UTF-8"));

String tempString = null;

int line = 1;

// 一次读入一行,直到读入null为文件结束

while ((tempString = reader.readLine()) != null) {

// 显示行号

System.out.println("line " + line + ": " + tempString);

if(line==4){

//此处为你自己设定的文件中代表成绩的位置

tempString = tempString.substring(0, 37)+grede+tempString.substring(39, tempString.length());

System.out.println("line " + line + ": " + tempString);

}

bw.write(tempString);

bw.newLine();

line++;

}

reader.close();

} catch (IOException e) {

e.printStackTrace();

} finally {

if (reader != null) {

try {

reader.close();

} catch (IOException e1) {

}

}

if (bw != null) {

try {

bw.close();

} catch (IOException e1) {

}

}

}

}

}

需要自己d盘建立text1.txt,内容你自己根据要求,代码中写死的37和39为你要修改的成绩的位置。

效果图如下,中午给你写的记得采纳

如何用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写的代码,java写的代码怎么运行
当前URL:http://cdkjz.cn/article/hcooce.html
多年建站经验

多一份参考,总有益处

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

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

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220