各位大神,Java新手,以下代码帮看看,谢谢
add(new JLabel(lightIcon));
add(new JLabel(roomIcon));
这个里面传桐稿的参数不对局返孝,世樱你看看文档
初学者请求java源代码
class Car
{
// 车辆属性
private String brand; // 品牌
private double engineDisplacement;// 排气量
private double speed;// 当前速度
private boolean status;// 启动状态
private double maxSpeed;// 最大速度
public double getSpeed () {
return this.speed;
}
public Car(String brand, double engineDisplacement, double maxSpeed) {
this.brand = brand;
this.engineDisplacement = engineDisplacement;
this.maxSpeed = maxSpeed;
// 其他属性也要有初始值,不然执行出错。
this.speed = 0;
this.status = false;
}
/** 启动 */
public void start() {
this.status = true;
printNowStatus ();
}
/** 关闭(熄火) */
public void stop() {
// 只在速度为0时关闭(貌似楼上两位没仔细看题…)
if (this.speed == 0)
{
this.status = false;
}
printNowStatus ();
}
/** 加速 */
public void speedUp() {
// 只在启动时可以加速
if (this.status)
{
this.speed = this.speed + 20;
if (this.speed this.maxSpeed)
{
this.speed = this.maxSpeed;
}
}
printNowStatus ();
}
/** 减速 */
public void slowDown() {
// 只在启动时可以减速
if (this.status)
{
this.speed = this.speed - 10;
if (this.speed 0)
{
this.speed = 0;
}
}
printNowStatus ();
}
/** 状态打印,在每次启动陆蚂,加减速,关闭时调用 */
private void printNowStatus () {
System.out.println("轿车早弯埋【" + this.brand + "】现在的启动状态是:" + this.status + "速度是:" + this.speed +"。");
}
}
public class TestCar
{
public static void main(String[] args)
{
Car myCar = new Car ("红旗", 2, 120);
//启动
myCar.start();
// 循环加速闹空到120
while (myCar.getSpeed() 120)
{
myCar.speedUp();
}
//循环减速
while (myCar.getSpeed() 0)
{
myCar.slowDown();
}
//关闭
myCar.stop();
}
}
/* 直接拿文本写的,我用的电脑没装jdk,楼主自己到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代码
public class Message {
public static void main(String[] args){
String name;
int age;
System.out.println("请输入姓名,回车结束:"); //提示输入
Scanner sc = new Scanner(System.in);
name = sc.nextLine(); //为变量赋值
System.out.println("请信敬谈输入年龄,回车结束:");
age = sc.nextInt();
System.out.println("姓名:"+name+"\n年龄:"+age); /滑碰/打印姓名及年龄
}
}
//不知道这样稿敬行么?
一个简单的Java程序代码?
package com.zpp;public class Charge {
public static void main(String [] args) {
if(args.length ==0) {
System.out.println("parameter error!");
System.out.println("java com.zpp.Charge [int]"庆陵);
return;
}
int min = Integer.parseInt(args[0]);
double money = 0.0;
if (min = 0) {
money =0.0;
System.out.println("not money");
} else if (min = 60) {
money = 2.0;
} else {
money = 2.0 + (min - 60) * 0.01;
}
System.out.println("please pay: "猛差茄 + money);
}
} 编枝察译:javac -d . Charge.java运行:java com.zpp.Charge 111
给段最简单的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!