My code can take in 3 arguments and once it does it is suppo

My code can take in 3 arguments, and once it does it is supposed to do two things. First, it should print out the individual characters of the second parameter. Next, it is supposed to take in that second parameter, and print it out backwards.

For example, if my argument was $ ./code hello world, it would print:
w
o
r
l
d
dlrow

However, instead it is printing:
w
o
r
l
d
dlrowollehedoc/.edoc/.=htap_elbatucexe

Here is my code below:

Can someone help me figure out how get just the second parameter?

int main(int argc, char argvD) int i 0; while argv[2] 10) i++ print (\"%cln\", argv[2] int j 0; while argv12] 10\') printf(\"%c\' argv[2]--)

Solution

JAVA PROGRAM;
import java.util.*;
public class cheggexample {
   public static void main(String[] args) {
       // TODO Auto-generated method stub
       Scanner sc=new Scanner(System.in);
       System.out.println(\"enter string:\");
       String name=sc.nextLine();
       String arr[]=name.split(\" \");
       String first=\"\";
       String second=\"\";
       for(int i=0;i<arr.length;i++){
           if(i==0)
           first=arr[0];
           else
               second=arr[1];
          
       }
       //System.out.println(first);
       //System.out.println(second);
       revstring(first,second);
   }
   private static void revstring(String first,String second) {
       for(int i=0;i<second.length();i++){
           System.out.println(second.charAt(i));
       }
       for(int i=second.length()-1;i>=0;i--){
           System.out.print(second.charAt(i));
       }
      
   }
}

OUTPUT:
enter string:
hello world
w
o
r
l
d
dlrow

code for:dlrow
int len=strlen(argv[2]);
while(len>=0){
printf(\"%c\",name[len]);
len--;
}
output:
dlrow

My code can take in 3 arguments, and once it does it is supposed to do two things. First, it should print out the individual characters of the second parameter.
My code can take in 3 arguments, and once it does it is supposed to do two things. First, it should print out the individual characters of the second parameter.

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site