0

can anyone tell
how to write in core java using command line arguments :
a) to print prime numbers from 1 to n
b) to calculate the length of input string
c) to find whether the number is odd or even
d) to convert dollar in rupees
e) to accept 3 command line arguments from users and display it in the sorted order

f) to accept string and interchange the first character with the last character

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by javaAddict
0

Your gonna have to make some sort of attempt here, no will really give you all the code you need.

0

COMMAND LINE:

> java YourClass arg1 arg2 "arg3 arg4"

public class YourClass {
   public static void main(String [] [B]args[/B]) {

      System.out.println("Number of Arguments: "+[B]args[/B].length);       

      for (int i=0;i<[B]args[/B].length;i++) {
           System.out.println([B]args[/B][i]);
      }
   }
}

The arguments at the command line are passed in the args array. If no arguments given, it has length 0. It is never null.

The above will return:

Number of Arguments: 3
arg1
arg2
arg3 arg4 // this is the third argument. The double quotes allow you to have spaces inside an argument

Use for loops, take a look at the String class API, use the '%' operator, post code

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.