本文介绍了我的程序打印出奇怪的结果:循环@ 530daa循环@ 530daa循环@ a62fc3循环@ a62fc3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么会发生这种情况还是有特殊原因还是出于很多不同的原因?我不知道为什么我的程序打印出它正在打印的值,因为我希望它打印出整数。相反,我得到这个:

Is there a particular reason why this would happen or can it be for a lot of different reasons? I have no idea why my program is printing out the values that it is printing, because I was expecting it to print out integers. Instead I am getting this:

循环@ 173a10f
循环@ a62fc3
循环@ a62fc3
循环@ a62fc3
循环@ 530daa
cycle @ a62fc3
cycle @ a62fc3
cycle @ 530daa
cycle @ a62fc3

cycle@173a10fcycle@a62fc3cycle@a62fc3cycle@a62fc3cycle@530daacycle@a62fc3cycle@a62fc3cycle@530daacycle@a62fc3

这是代码:(我也有一个循环类,一个堆栈和队列类)

This is part of the code: (I also have a cycle class, and a stack and queue class)

  import java.io.*;
   import java.util.*;

public class PrintQ {

  public static void main(String args[]) throws FileNotFoundException {

     Scanner inFile = new Scanner(new FileReader("C:\\Users\\Whitney\\Desktop\\QueueIn.txt"));
     String job1;
     job1=inFile.next();

     char char1;
     int i=0;
     int FirstComma;
     int SecondComma;
     String charholder;

     QueueClass<cycle> list= new QueueClass(100);
     QueueClass<Integer> cyclelist= new QueueClass(100);
     cycle currentcycle= new cycle();
     cycle priorityCycle= new cycle();
     cycle Scycle= new cycle();


     while(inFile.hasNext()){

        switch(job1.charAt(0)) {

           case 'q': 
              {
                 FirstComma=job1.indexOf(',');
                 SecondComma=job1.lastIndexOf(',');
                 currentcycle.jobNumber=Integer.parseInt(job1.substring(FirstComma+1,SecondComma));
                 currentcycle.cycleNumber=Integer.parseInt(job1.substring(SecondComma+1));
                 cyclelist.addQueue(currentcycle.cycleNumber);
                 list.addQueue(currentcycle);  
                 break;
              }

           case 'p': 
              {                    
                 FirstComma=job1.indexOf(',');
                 SecondComma=job1.lastIndexOf(',');
                 priorityCycle.jobNumber=Integer.parseInt(job1.substring(FirstComma+1,SecondComma));
                 priorityCycle.cycleNumber=Integer.parseInt(job1.substring(SecondComma+1));
                 cyclelist.addQueue(priorityCycle.cycleNumber);
                 list.priorityinsert(priorityCycle);
                 break;
              }

           case 's': 
              {
                 FirstComma=job1.indexOf(',');
                 SecondComma=job1.lastIndexOf(','); 
                 Scycle.cycleNumber=Integer.parseInt(job1.substring(SecondComma+1));
                 list.addQueue(Scycle);
                 cyclelist.addQueue(Scycle.cycleNumber);
                 break;
              }

           case 'h': 
              {
                 StackClass<Integer> stackjob= new StackClass();
                 StackClass<Integer> stackcycle= new StackClass();
                 job1=(String) inFile.next();

                 while(inFile.hasNext()){

                    switch(job1.charAt(0)) {

                       case 'q':
                          {
                             FirstComma=job1.indexOf(',');
                             SecondComma=job1.lastIndexOf(',');
                             currentcycle.jobNumber=Integer.parseInt(job1.substring(FirstComma+1,SecondComma));
                             currentcycle.cycleNumber=Integer.parseInt(job1.substring(SecondComma+1));
                             stackjob.push(currentcycle.jobNumber);
                             stackcycle.push(currentcycle.cycleNumber);
                             break;
                          }
                       case 'p':
                          {
                             FirstComma=job1.indexOf(',');
                             SecondComma=job1.lastIndexOf(',');
                             priorityCycle.jobNumber=Integer.parseInt(job1.substring(FirstComma+1,SecondComma));
                             priorityCycle.cycleNumber=Integer.parseInt(job1.substring(SecondComma+1));
                             stackjob.push(priorityCycle.jobNumber);
                             stackcycle.push(priorityCycle.cycleNumber);
                             break;
                          }

                       case 's':
                          {
                             FirstComma=job1.indexOf(',');
                             SecondComma=job1.lastIndexOf(',');
                             Scycle.cycleNumber=0;
                             Scycle.cycleNumber=Integer.parseInt(job1.substring(SecondComma+1));
                             stackjob.push(0);
                             stackcycle.push(Scycle.cycleNumber); 
                             break;
                          }

                       case 'h': 
                          {
                             continue;
                          }

                    }
                    job1=(String) inFile.next();

                 }   
                 System.out.println();
                 System.out.println();

                 while((stackjob.isEmptyStack()==false) && (stackcycle.isEmptyStack()==false)) 
                 {
                    int printjob;
                    int printcycle;
                    Object peek;

                    printjob=stackjob.peek();
                    printcycle=stackcycle.peek();
                    System.out.println("Job Number: "+printjob+" "+"Cycles Remaining: "+printcycle);
                    stackcycle.pop();
                    stackjob.pop(); 

                 } 

                 continue;
              }           
        }
        job1=inFile.next();   
     }   

     cycle whilecurrent= new cycle();

     while(list.isEmptyQueue()==false) 
     {
        whilecurrent=list.front();
        int whilecurrentcycle= cyclelist.front();
        list.print();
        //System.out.println();

        while(whilecurrentcycle != 0)
        {
           whilecurrentcycle--;
           //System.out.println("loop "+whilecurrentcycle);  
        }
        //System.out.println();
        //System.out.println(whilecurrent);

        cyclelist.deleteQueue();
        list.deleteQueue();   
     }  
     System.out.println();
     list.print();
     System.out.println(); 
  }

}

推荐答案

在某处您正在打印循环对象,因为您还没有覆盖 cycle.toString(),它使用。

Somewhere you're printing cycle objects, and since you haven't overridden cycle.toString(), it's using the default toString implementation.

覆盖 toString 类的方法,你需要编写如下代码:

To override the toString method of a class, you would need to write some code like below:

class Xxx {
    @Override
    public String toString() {
         StringBuilder sb = new StringBuilder();
         sb.append("Your");
         sb.append("Logic Here");
         return sb.toString();
    }
}

这篇关于我的程序打印出奇怪的结果:循环@ 530daa循环@ 530daa循环@ a62fc3循环@ a62fc3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 00:18