小编Tit*_*iuM的帖子

Java - 扫描程序注释跳过

我在本实验中的任务是接受多个输入文件,并且所有这些文件的格式都相似,只是有些文件有注释,我想跳过注释行.例如:

输入文件:

Input file 1

#comment: next 5 lines are are for to be placed in an array
blah 1
blah 2
blah 3 
blah 4
blah 5

#comment: next 2 line are to be placed in a different array
blah 1 
blah 2

#end of input file 1
Run Code Online (Sandbox Code Playgroud)

我尝试做的是我使用2循环(如果需要,我可以发布我的代码).我做了以下

while(s.hasNext()) {
    while(!(s.nextLine().startWith("#")) {
        //for loop used to put in array
        array[i] = s.nextLine();
    }
}
Run Code Online (Sandbox Code Playgroud)

我觉得这应该有效,但事实并非如此.我做错了什么 请帮忙.先感谢您.

java java.util.scanner

2
推荐指数
1
解决办法
4117
查看次数

Java - 使用数组的有界队列

我被要求创建一个有条件的队列类,其条件如下:

仅使用基本类型,实现有界队列以存储整数.应针对算法运行时,内存使用和内存吞吐量优化数据结构.不应导入和/或使用外部库.解决方案应该在一个提供以下功能的类中提供:

  • 构造函数 - 类应该为对象创建提供一种方法,该方法采用整数来设置队列的大小.
  • enqueue - 如果队列未满,则函数应采用整数并将其存储在队列中.该函数应该正确处理队列已满的情况.
  • dequeue - 如果当前存储在队列中,则函数应返回一个整数.该函数应该正确处理队列为空的情况.

我写了这个课程,但我想通过让某人测试它以及看它是否正常工作来寻求帮助.我写了一个小的主要类来测试它,一切似乎都在工作但我想在提交它之前想看另一双眼睛.它是为了实习.先感谢您.

public class Queue<INT>
{


    int size;
    int spacesLeft;
    int place= 0;
    int[] Q;


    public Queue(int size)
    {
        this.size = size;
        spacesLeft = size;
        Q = new int[size];
    }

    //enqueue - function should take an integer and store it in the queue if the queue isn't full.
    //The function should properly handle the case where the queue is already full
    public void enque(int newNumber) throws Exception
    {
        if(place <= …
Run Code Online (Sandbox Code Playgroud)

java

1
推荐指数
1
解决办法
9103
查看次数

标签 统计

java ×2

java.util.scanner ×1