public class MyFirstApp
{
public static void main(String[] args)
{
System.out.print("Hello world")
}
}
“hello world”就是应该是所有学java的新手看的第一个代码了。如果是零基础的新手朋友们可以来我们的java实验班试听,有免费的试听课程帮助学习java必备基础知识,有助教老师为零基础的人提供个人学习方案,学习完成后有考评团进行专业测试,帮助测评学员是否适合继续学习java,15天内免费帮助来报名体验实验班的新手快速入门java,更好的学习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("不能构成三角形")
}
}