简体   繁体   English

为什么我不能在课堂上调用我的方法

[英]Why can't I call my method in my class

So the main method in my class looks like this: 所以我班上的主要方法是这样的:

public static void main(String[] args) {
    String text = "stuff";
    VigenereCipher t = new VigenereCipher(text);
    t.stringToIntArray(text);
    VigenereCipher s = new VigenereCipher(text);
    s.intArrayToString(t);

The problem is in the first method it takes a string and converts it to an int[] however the problem is when I try to call the second method (which converts the int[] back to a string) it says that t is a VigenereCipher and not an int[]. 问题在于第一个方法需要一个字符串并将其转换为int [],但是问题是当我尝试调用第二个方法(它将int []转换回字符串)时,它说t是一个VigenereCipher而不是int []。 So how do I call the method in my class so that t is an int[] and not a VigenereCipher object? 那么,如何在类中调用该方法,使t为int []而不是VigenereCipher对象?

You have to pass the int[] returned by the stringToIntArray method, not the VigenereCipher object. 您必须传递stringToIntArray方法而不是VigenereCipher对象返回的int[] For example: 例如:

String text = "stuff";
VigenereCipher t = new VigenereCipher(text);
int[] intArray = t.stringToIntArray(text);
VigenereCipher s = new VigenereCipher(text);
s.intArrayToString(intArray);

But I'm not sure if this does what you want. 但是我不确定这是否满足您的要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM