【发布时间】:2019-05-15 20:22:31
【问题描述】:
所以我已经看了几天关于类、引用和方法的大量帖子,设置和获取。我似乎无法理解这一切是如何运作的。
免责声明是的,这是针对课堂作业的,下面这个糟糕的例子是为了说明。非常感谢您的帮助。
我已经有一个有效的程序(尽管程序非常初级且效率低下)。然而,我所拥有的一切都在我的 Primary 类的 main 方法中,我需要将它的一部分放在一个单独的类中并让它仍然可以工作。
使用 main 方法,用户输入明文密码 (clearText),其中提供的 sn-p 代码将密码散列为 (hashText)。然后将其用于其他事情。
我希望完成的是将密码的sn-p从我的主类的主要方法中分离出来,进入一个单独的辅助类。
我不知道该怎么做。如何将clearText导入二级类,然后将hashText输出回一级类中的main方法。
谢谢。
import java.util.*;
import java.io.*;
public class Primary {
public static void main(String[] args) throws Exception {
String clearText = ("");
System.out.print("Type Text");
clearText = scnr.next();
//Somehow export clearText to the secondary class
//Somehow import hashText into the main method for further use
System.out.println(hashText);
}
}
public class Secondary {
String hashText = ("");
//Somehow import clearText value inputted but the user
//here is where clearText gets hashed(I have that)
//Somehow export hashText for use in the main method
}
【问题讨论】:
-
你真的需要使用“Secondary”类吗?如果没有,为什么不使用一个简单的方法接收 clearText 并返回其散列内容。