运行java程序时javac -d . Test.java,为什么用-d.

运行java程序时javac -d . Test.java,为什么用-d.,第1张

这不是运行java程序,这是编译java源码,其中:

javac是java的编译器名;-d是编译器的参数选项,用来指定生成的包目录和class文件的根目录,表示将根目录指定为当前目录;Testjava是源文件名。

假设源文件Testjava中有如下包语句:package AB;

则生成的Testclass文件保存在路径\A\B\Testclass中。

如果没有包语句,则Testclass文件保存在路径\Testclass中。

import javautilScanner;

public class TestUser {

public static void main(String[] args) {

User user = new User("Zhang san", "abcdefg");

Systemoutprintln(usertoString());

Scanner scanner = new Scanner(Systemin);

Systemoutprint("Please input old password:");

String oldPassword = scannernext();

Systemoutprint("Please input new password:");

String newPassowd = scannernext();

usersetPassword(oldPassword, newPassowd);

Systemoutprintln(usertoString());

}

}

class User{

private String userName;

private String password;

private static int userNumber = 0;

public User(){

userNumber += 1;

userName = "unknown";

password = "123456";

}

public User(String userName){

userNumber += 1;

thisuserName = userName;

password = "123456";

}

public User(String userName, String password){

userNumber+=1;

thisuserName = userName;

thispassword = password;

}

public void setPassword(String oldPassword,String newPassword){

if(oldPasswordequals(password)){

password = newPassword;

Systemoutprintln("Password set success");

}else{

Systemoutprintln("Password set not success");

}

}

public String toString(){

return "Username : " + thisuserName + ", Password: " + thispassword;

}

}

-----------------------

Username : Zhang san, Password: abcdefg

Please input old password:abcdefg

Please input new password:1234567

Password set success

Username : Zhang san, Password: 1234567

我做的有点类似但不是完全一样 发给你看看有没有启发。

public class MyPoint{

public static void main(String[] args){

MyPoint mp =new MyPoint();

mpsetStart(new Point(10,10));

mpsetEnd(new Point(20,20));

//mpsetstray(mpgetend());

mpsetStray(new Point(30,30));

Systemoutprintln(mpgetstray());

Systemoutprintln(mpgetstart());

Systemoutprintln(mpgetend());

}

private Point start;

private Point end;

private Point stray;

public Point getstart(){

return start;

}

public void setStart(Point start){

thisstart=start;

}

public Point getend(){

return end;

}

public void setEnd(Point end){

thisend=end;

}

public Point getstray(){

return stray;

}

public void setStray(Point stray){

thisstray=stray;

}

public MyPoint() {

}

public MyPoint(Point start, Point end ,Point stray) {

super();

thisstray = stray;

thisstart = start;

thisend = end;

}

}

class Point{

public String toString(){

return "x:"+ x +"y"+ y ;

}

private int x;

private int y;

public int getx(){

return x;

}

public void setx(int x){

thisx=x;

}

public int gety(){

return y;

}

public void sety(int y){

thisy=y;

}

public Point (int x,int y){

thisx=x;

thisy=y;

}

}

class Shape {

protected int length;

protected int width;

public int area(){

return lengthwidth;

}

}

class Square extends Shape{

private int length;

private int width;

public Square(int length,int width) {

thislength = length;

thiswidth = width;

}

public int area(){

return lengthwidth;

}

}

public class JavaTest {

public static void main(String[] args){

Square mySq = new Square(2,2);

Systemoutprintln(mySqarea());

}

}

以上就是关于运行java程序时javac -d . Test.java,为什么用-d. 全部的内容,包括:运行java程序时javac -d . Test.java,为什么用-d. 、编写一个完整的Java 程序,包括User和TestUser两个类。、JAVA程序 请帮忙写出TestMyPoint类的源代码等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/9723240.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-01
下一篇 2023-05-01

发表评论

登录后才能评论

评论列表(0条)

保存