Write the definition of a method named copy receives a refer

Write the definition of a method  named  copy receives a reference to a Scanner object associated with a stream of input. Themethod reads all the Strings remaining to be read from the stream and displays them, one on a line with no other spacing IN REVERSE ORDER, onto standard output . So if the input were:
    here comes
    the sun
the output would be:
    sun
    the
    comes
    here

The method must not use a loop of any kind (for, while, do-while) to accomplish its job.

Solution

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
public class maind1 {

   public static void main(String[] args) {
       Scanner sc=new Scanner(System.in);
       System.out.println(\"enter sentence to reverse:\");
       String original=sc.nextLine();
       StringBuffer rev;
       rev=findreverse(original);
       System.out.println(rev);
  
      
   }

   private static StringBuffer findreverse(String original) {
       String org=original;
       StringBuffer sb=new StringBuffer(org);
       sb.reverse();
         
         
       return sb;
   }

output:

enter sentence to reverse:
seris if exoabsui
iusbaoxe fi sires

Write the definition of a method named copy receives a reference to a Scanner object associated with a stream of input. Themethod reads all the Strings remainin

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site