java - Getting an input from command-line and passing it to a method -
I am getting a string ARE from the command line and it displays the user as an integer array. What can be the mistake here?
import java.lang.String; Convert to public square array {string stray []; Public int [] Strostrointrerer (String Strawre []) {int intArray [] = New Int [Strawre.line]; {IntArray [count] = Integer.parseInt (strArray [count]) for (int count = 0; count & lt; strArray.length; count ++); } Return intArray; } Public Zero display array (int intArray []) {for (int j = 0; j & lt; intArray.length; j ++) {System.out.println (intArray [j]); }} Public static zero main (string [] args) {arrayConvert array_convert = new arrayConvert (); Array_convert.StrArrtoIntArr (args); Array_convert.displayArray (intArray); }}
You forgot to save the intermediate result in the main category:
public static zero major (string [] args) {arrayConvert array_convert = new arrayConvert (); Int [] intArray = array_convert.StrArrtoIntArr (args); Array_convert.displayArray (intArray); }
There are some more things in your code, you might want to check it out:
-
import java.lang.String;
You do not need to include it Java.lang is automatically imported. -
string stray [];
This variable is never used in the variablestrArray []
in theStrArrtoIntArr
different variable in the different (local) area is confused with global variables It is possible.
Comments
Post a Comment