[英]Why does println not show up - Java
I am a newb with Java so don't bite me please.. I've made this method, but it will not show up in the console screen, why? 我是Java的新手,所以请不要咬我...我已经制作了这个方法,但它不会出现在控制台屏幕上,为什么?
public class ADSopgave2K1 {
public static void main(String[] args) {
}
public void print(String s, int pos) {
s = "";
pos = s.length();
int count = s.length();
char[] ray;
System.out.println("Enter a word: ");
Scanner userInputF = new Scanner(System.in);
s = userInputF.nextLine();
ray = s.toCharArray();
for (int t = 0; t < s.length(); t++) {
System.out.println(ray[t]);
return;
}
}
}
You did not call that method yet. 你还没有调用那种方法。 Try to call your method. 尝试调用您的方法。
public static void main(String[] args) {
ADSopgave2K1 intance=new ADSopgave2K1();
intance.print();
}
Edit 编辑
public void print() {
System.out.println("Enter a word: ");
Scanner userInputF = new Scanner(System.in);
String s = userInputF.nextLine();
char[] ray = s.toCharArray();
for (int t = 0; t < s.length(); t++) {
System.out.println(ray[t]);
}
}
When you run your program, Java will call main(String[] args)
. 运行程序时,Java将调用main(String[] args)
。
But this is an empty function, so you will not see any output. 但这是一个空函数,所以你不会看到任何输出。
Becasue, you did not call anything in main(String[] args)
method. 但是,你没有在main(String[] args)
方法中调用任何东西。 Make your print method static
and call this to your main method. 使您的打印方法保持static
并将其调用到您的main方法。
public static void print(String s, int pos){
}
EDIT: 编辑:
public static void main(String[] args){
print("test",1);
}
您必须通过为您的类创建实例来调用main()中的方法
ADSopgave2K1 r=new ADSopgave2K1();
r.print("jai", 4);
Create an object of your class in side main method and then call its method. 在side main方法中创建类的对象,然后调用其方法。
You should call print() method. 你应该调用print()方法。
public class ADSopgave2K1 {
public static void main(String[] args)
{
print("Hello World", 1);
}
public void print(String s, int pos)
{
s = "";
pos = s.length();
int count = s.length();
char[] ray;
System.out.println("Enter a word: ");
Scanner userInputF = new Scanner(System.in);
s = userInputF.nextLine();
ray = s.toCharArray();
for (int t = 0; t < s.length(); t++) {
System.out.println(ray[t]);
return;
}
}
} }
either you make print method static and call it with correct argument Or 要么使print方法静态,要用正确的参数调用它
make instance of ADSopgave2K1 class and call it with correct args 制作ADSopgave2K1类的实例并使用正确的args调用它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.