I's trying to build an encoder like the "Enigma Machine" and I have this code so far where I'm trying to get comboOne() to use the "s" variable from main():

我正在尝试构建像“Enigma Machine”这样的编码器,到目前为止我有这个代码,我试图让comboOne()使用main()中的“s”变量:

import java.io.*;

public class main
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("What would you like to encode?");
        String s = br.readLine();

        s.toCharArray();
        System.out.println(s);

        //comboOne comboOne = new comboOne();
    }
}

Just to encode one letter I've written this:

只是编码一个字母我写了这个:

public class comboOne extends main
{
    main m = new main();
    char message = s.toCharArray();
        if(message == 'a')
    {
        System.out.println('b');
    }
}

I am quite new so apologies if I am making an obvious mistake but I think this would be a fun challenge for myself. Please send help and thanks for helping :)

如果我犯了一个明显的错误,我很新,所以道歉,但我认为这对我自己来说是一个有趣的挑战。请发送帮助并感谢您的帮助:)

1 个解决方案

#1


-1

Add outside your Main.main method

在Main.main方法之外添加

public static String s;

Then use Main.s to access the String in a static way. Since it is static it does not need to be instantiated an can directly be called from the class.

然后使用Main.s以静态方式访问String。由于它是静态的,因此不需要实例化,可以直接从类中调用。

更多相关文章

  1. JAVA 静态方法和静态变量和final和※静态import※
  2. java如何通过反射 激活静态类的静态方法

随机推荐

  1. matplotlib绘图技巧详解(一)
  2. 异步函数中的异常处理及测试方法 [每日前
  3. Python+Kepler.gl轻松制作酷炫路径动画
  4. Python笔下那些神奇的树
  5. 一文读懂 Kubernetes APIServer 原理
  6. 利用geopandas与PostGIS进行交互
  7. Python中最好用的6个地图可视化库
  8. Matplotlib如何绘制多个子图
  9. TypeScript 3.3发布!看看增加了什么新功能
  10. 高效的10个Pandas函数,你都用过吗?