public class VarGreet {
   public static void main(String[] args) {
        // TODO code application logic here
         printGreeting(args[0],args);
    }
    public static void printGreeting(String s, Integer...id) {
         for (Integer n : names) {
              System.out.println("Hello " + n + ". "); 
         }
    }
}
            Asked
            
        
        
            Active
            
        
            Viewed 1,244 times
        
    -3
            
            
         
    
    
        Timothy Truckle
        
- 15,071
- 2
- 27
- 51
 
    
    
        manish
        
- 1
- 3
- 
                    2`args` is an array of `Strings` change --> `Integer...id` to `String...id`, where is `names` declared ?. that aside what is the problem? what is your question? due to those reasons I am voting to close this question for "unclear what you're asking" – Ousmane D. Apr 27 '17 at 20:33
- 
                    1Possible duplicate of [How to convert a String to an int in Java?](http://stackoverflow.com/questions/5585779/how-to-convert-a-string-to-an-int-in-java) – Joe C Apr 27 '17 at 20:35
- 
                    how could i pass input to Integer...id in main, when i call the PrintGreeting – manish Apr 27 '17 at 22:15
- 
                    Yah, my mistake it will id there not names – manish Apr 27 '17 at 22:19
1 Answers
0
            In printGreeting you are looping over names (not id). Fix that first,
for (Integer n : id) {
    System.out.println("Hello " + n + ". ");
}
Then, assuming you are using Java 8+, you can start with the second argument and map everything to an Integer, collect that as a List and then convert that to an Integer[] like
printGreeting(args[0], Stream.of(args).skip(1).mapToInt(Integer::parseInt)
        .boxed().collect(Collectors.toList()).toArray(new Integer[] {}));
 
    
    
        Elliott Frisch
        
- 198,278
- 20
- 158
- 249