资讯

精准传达 • 有效沟通

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

java新手代码大全翻译 java新手代码大全翻译中文

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

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

创新互联从2013年创立,先为木兰等服务建站,木兰等地企业,进行企业商务咨询服务。为木兰企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

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.lp.test;

public class StringTest {

public static void main(String[] args) {

// TODO code application logic here

//打印main方法参数

if (args.length  0) {

for (int i = 0; i  args.length; i++) {

System.out.println(args[i]);

}

} else {

System.out.println("No args.");

}

String str = "12345";

//将str拆分为单个char输出

for (int i = 0; i  str.length(); i++) {

System.out.print(str.charAt(i) + " ");

}

System.out.println("");

//截取str前四位

str = str.substring(0, 4);

System.out.println(str);

//将截取后的str与"77777"进行拼接

str = str.concat("77777");

System.out.println(str);

//输出7在str中第一次出现的位置

int index = str.indexOf('7');

System.out.println(index);

//获取7在str中最后一次出现的位置

int lastIndex = str.lastIndexOf('7');

System.out.println(lastIndex);

//将str中的7全部换为6

str = str.replace('7', '6');

System.out.println(str);

//将str中第一次出现的"6666"置换为"5"

str = str.replaceAll("6666", "5");

System.out.println(str);

//初始化一个包含"12345"的字符串缓冲对象

StringBuilder strb = new StringBuilder("12345");

//循环输出字符串缓冲对象的内容

for (int i = 0; i  strb.length(); i++) {

System.out.print(strb.charAt(i) + " ");

}

System.out.println("");

//删除strb中索引为4的字符

strb.deleteCharAt(4);

System.out.println(strb);

//在删除字符后的strb中拼接"77777"

strb.append("77777");

System.out.println(strb);

//在索引为4芳容位置上插入"56";

strb.insert(4, "56");

System.out.println(strb);

//颠倒strb中的字符顺序

strb.reverse();

System.out.println(strb);

String hello = "HelloWord";

//将hello字符串转换为全小写

System.out.println(hello.toLowerCase());

//将hello字符串转换为全大写

System.out.println(hello.toUpperCase());

}

}

java新手,求完整的源代码

//都是从新手过来的,以下代码供参考

//1.

public class BankAccount {

private static String acctnum;

private static double money;

private static void showAcct() {

System.out.println("账号为: " + acctnum);

}

private static void showMoney() {

System.out.println("余额为: " + money);

}

public BankAccount(String acc, double m) {

this.acctnum = acc;

this.money = m;

}

public static void main(String[] args) {

BankAccount ba = new BankAccount("626600018888", 5000.00);

ba.showAcct();

ba.showMoney();

}

}

//2.

public class Triangle {

private static float a;

private static float b;

private static float c;

public Triangle(float a, float b, float c) {

this.a = a;

this.b = b;

this.c = c;

}

public static boolean judgeTriangle(float a, float b, float c) {

if ((a  Math.abs(b - c)  a  b + c)

 (b  Math.abs(a - c)  b  a + c)

 (c  Math.abs(a - b)  c  a + b))

return true;

else

return false;

}

public float getCircumference() {

return this.a + this.b + this.c;

}

}

//3.

public class TestTriangle {

public static void main(String[] args) {

Triangle t = new Triangle(5.3f,7.8f,9.3f);

if(t.judgeTriangle(5.3f,7.8f,9.3f)){

System.out.print("能够成三角形,周长为: ");

System.out.printf("%9.2f",t.getCircumference());}

else

System.out.println("不能构成三角形");

}

}

求翻译解释一下Java代码

public class Test{

public static String output=" ";

public static void foo(int i){

try{

if(i==1){

throw new Exception();//如果参数为1,抛出异常,进入到catch

}

output+="1";

}catch(Exception e){

output+="2";//如果参数为1,执行这里

return;

}finally{

output+="3";//不管怎样这里都要执行

}

output+="4";//这里是最后一个执行语句,抛出异常就不执行这里

}

public static void main(String[] args){

foo(0);//第一次调用

foo(1);//第二次调用

System.out.println(Test.output);

}

}

/*

* 现在说下执行步骤:output的值我[]括起来

* 第一次调用foo(0):(1)参数为0,所以执行output+="1",那么output现在为[ 1];

*      (2)执行到output+="3",那么output现在为[ 13];

*      (3)执行到output+="4";那么output现在为[ 134]

* 第二次调用foo(1):(1)执行if里面,抛出异常

*      (2)进入到catch,执行output+="2",output现在为[ 1342]

*      (3)进入finally,执行output+="3", output现在为[ 13423]

*/


分享题目:java新手代码大全翻译 java新手代码大全翻译中文
当前网址:http://cdkjz.cn/article/hpdcjc.html
多年建站经验

多一份参考,总有益处

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

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

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