在两个给定的整数之间打印整数 [英] Printing integers between 2 given integers

查看:191
本文介绍了在两个给定的整数之间打印整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用一个方法创建一个类,打印任何两个给定整数之间的所有整数。这是我现在得到的 -

  public class IntList {
public static void main(String [] args ){
int start = Integer.parseInt(args [0]);
int stop = Integer.parseInt(args [1]);
for(int i = start + 1; i System.out.print(i);













这将不能编译,我得到2个错误,说:解析时到达文件的结尾,第4和第5行每一次。

解决方案

错误 main()方法声明。您必须传递一个数组作为此函数的唯一参数。

然后或者声明您的开始停止变量作为本地变量,然后在main方法本身内部完成这个工作,或者从 main()方法创建一个新的函数。



没有更多的解释需要,这是Java的基础知识。您应该阅读Java课程。


I'm trying to create a class with a method that prints all integers between any two given integers. This is what I've got now-

public class IntList {
public static void main(String[] args) {
int start = Integer.parseInt(args[0]);
int stop = Integer.parseInt(args[1]);
for (int i = start + 1; i < stop; i++) {
System.out.print(i);
}
}

}

This won't compile, I get 2 errors saying "reached end of file while parsing", once each for lines 4 and 5.

解决方案

Wrong main() method declaration. You have to pass an array as the only parameter for this function.

Then either declare your start and stop variables as local, and do the job inside the main method itself, or create a new function you call from the main() method.

No more explanation needed, this is Java basics. You should read a Java lesson.

这篇关于在两个给定的整数之间打印整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆