Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3232636
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:11:03+00:00 2026-05-17T17:11:03+00:00

import java.io.*; import java.lang.*; public class Propogate1 { String reverse(String name) { if(name.length()==0) throw

  • 0
import java.io.*;
import java.lang.*;

public class Propogate1
{

String reverse(String name)
{
if(name.length()==0)
    throw IOException("name");

String reverseStr="";
for(int i=name.length()-1;i>0;--i)
{
  reverseStr+=name.charAt(i);

}
return reverseStr;
}

public static void main(String[] args)throws IOException
{
String name;
try
{
        Propogate1 p=new Propogate1();
    p.reverse("java");

}
finally
{
System.out.println("done");
}

}

}

I have to create a class propogate and main method which will call reverse(). In that if the name.length is null, it will throw an exception. If it is not null it will reverse the string. Pls help me

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T17:11:03+00:00Added an answer on May 17, 2026 at 5:11 pm

    May be this is what you need.

    package reversestring;
    
    // import java.io.* is not needed here. 
    // And if you want to import anything,
    // prefer specific imports instead and not entire package.
    
    // java.lang.* is auto-imported. You needn't import it explicitly.      
    
    public class Propogate {
      // There's no reason this method should be an object method. Make it static.
      public static String reverse(String name) {
        if (name == null || name.length() == 0) {
          // RuntimeExceptions are preferred for this kind of situations.
          // Checked exception would be inappropriate here.
          // Also, the error message should describe the kind of exception
          // occured.
          throw new RuntimeException("Empty name!");
        }
        // Idiomatic method of string reversal:
        return new StringBuilder(name).reverse().toString();
      }
    
      public static void main(String[] args) {
        String name;
        try {
          name = Propogate.reverse("java");
          System.out.println("Reversed string: " + name);
        } catch (RuntimeException rx) {
          System.err.println(rx.getMessage());
        } finally {
          // I don't get the point of `finally` here. Control will reach this
          // point irrespective of whether string reversal succeeded or failed.
          // Can you explain what do you mean by "done" below?
          System.out.println("done");
        }
      }
    }
    

    /*

    Output:-

    Reversed string: avaj

    done

    */

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

import java.lang.System; public class Splitter{ public static void main(String args[]){ String path_separator = Path
import java.lang.Math; public class NewtonIteration { public static void main(String[] args) { System.out.print(rootNofX(2,9)); }
import java.lang.Process; import java.io.*; import java.io.InuputStream; import java.io.IOException; public class newsmail{ public static void
import java.lang.Process; import java.io.*; import java.io.InputStream; import java.io.IOException; public class prgms{ public static void
import java.io.IOException; import java.util.*; public class calling { public static String s; public static
import java.util.Scanner; import java.lang.String; public class Test { public static void main(String[] args) {
import java.lang.reflect.Method; import java.util.Arrays; public class Test { public static void main(String s[]) throws
This is my java file : import java.io.File; import java.lang.String; public class ListFiles {
Consider this example : import java.lang.reflect.Field; public class Test { public static void main(String[]
Demo code: import java.lang.ref.PhantomReference; import java.lang.ref.ReferenceQueue; public class Main { public static void main(String[]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.