java初学代码 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("不能构成三角形");
}
}
JAVA初学,几句代码,求解释!
import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.swing.*;
public class Server{
public static void main(String args[]) throws IOException {
String str="exit";
String str2;
do{
System.out.print("请输入:");
BufferedReader str1= new BufferedReader(new InputStreamReader(System.in));
str2 =str1.readLine();
}while(str2.equals(str)==false);
System.out.println("恭喜你跳出了");
}
}
JAVA初学代码问题!
1. value建议这样声明: private int value;
2. isEven()、isOdd()、isPrime() 这三个方法体为甚不判断 this.value,非要再重新传值,这个与设计初衷相悖了吧
3. int类型的值可以直接比较,方法可以这样写:
public boolean equals(int x) {
return this.value == x;
}
网站题目:java初学代码 java编程基础代码
当前网址:http://myzitong.com/article/hpihic.html