我如何调用从私有方法数组

我如何调用从私有方法数组

本文介绍了我如何调用从私有方法数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我不得不做出这样的创建结果的应用程序,我已经完成了一切,我觉得????但我不知道如何让我的私有方法outputData输出数组结果从私有方法的getValue。

这是我所

  // CreateResults.java
//创建民意调查结果,并将其输出到文件。
进口java.io.FileNotFoundException;
进口的java.util.Formatter;
进口java.util.FormatterClosedException;
进口java.util.IllegalFormatException;
进口java.util.NoSuchElementException;
进口java.util.Scanner中;公共类CreateResults
{
   私人诠释的getValue()
   {
         INT []结果= {1,1,1,1,1,2,2,3,3,4,5,6,7,8,9};
         outputData(结果);   } // end方法的getValue   私人无效outputData(INT []输出)
   {         对于(INT行= 0;&行LT; results.length;排++){
         的System.out.println(输入[行]);
   } //结束了
   } // end方法outputData   公共静态无效的主要(字符串ARGS [])
   {
      CreateResults应用=新CreateResults();
      application.outputData();
   } //主到底
} //结束类CreateResults


解决方案

要得到你的code工作,你将需要的getValue 公众(和它不返回任何东西,使它无效)

然后在你的然后你可以再调用 application.getValue()这将创建数组,然后叫 outputData

 公共无效的getValue()
{
     INT []结果= {1,1,1,1,1,2,2,3,3,4,5,6,7,8,9};
     outputData(结果);} // end方法的getValue公共静态无效的主要(字符串ARGS [])
{
  CreateResults应用=新CreateResults();
  application.getValue();
} //

此外,你 outputData 正在输出的输入参数你需要将其更改为

 私人无效outputData(INT []输出)
 {     对于(INT行= 0;&行LT; output.length;排++){
         的System.out.println(输出[行]);
     }
 } //ê

so, i have to make an application that creates results, i have completed everything, I think???? but i dont know how to get me private method outputData to output the array results from the private method getValue.

This is what i have

 // CreateResults.java
// Create poll results and output them to a file.
import java.io.FileNotFoundException;
import java.util.Formatter;
import java.util.FormatterClosedException;
import java.util.IllegalFormatException;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class CreateResults
{
   private int getValue()
   {
         int[]results = { 1, 1, 1, 1, 1, 2, 2, 3, 3, 4, 5, 6, 7, 8, 9 };
         outputData(results);

   } // end method getValue

   private void outputData(int[] output)
   {

         for (int row = 0; row < results.length; row++) {
         System.out.println(input [row]);
   }//end for
   } // end method outputData

   public static void main( String args[] )
   {
      CreateResults application = new CreateResults();
      application.outputData();
   } // end main
} // end class CreateResults
解决方案

To get your code to work, you will need to make getValue public (and as it does not return anything, make it void)

Then within your main you can then then call application.getValue() which will create your array and then call outputData

public void getValue()
{
     int[]results = { 1, 1, 1, 1, 1, 2, 2, 3, 3, 4, 5, 6, 7, 8, 9 };
     outputData(results);

} // end method getValue

public static void main( String args[] )
{
  CreateResults application = new CreateResults();
  application.getValue ();
} //

Also as you outputData is working on the inputted parameter of output you need to change it to

 private void outputData(int[] output)
 {

     for (int row = 0; row < output.length; row++) {
         System.out.println(output[row]);
     }
 }//e

这篇关于我如何调用从私有方法数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 07:48