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

  • SEARCH
  • Home
  • 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 8380213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:23:56+00:00 2026-06-09T16:23:56+00:00

I’m working on a translator that converts English to Morse code and the other

  • 0

I’m working on a translator that converts English to Morse code and the other way around. I wrote the code and am able to compile it but after enter the sentence which I want convert, the command prompt dash just goes to the next line and nothing comes out. Is it an problem with my code?

This is my code:
( not the most efficient as I’m still new to java so any tips would be appreciated as well)

import javax.swing.JOptionPane;

public class translator {
    public static void main ( String [] args ) {

        String s1 = "Morse";

        //Decide whether Morse code or English
        String decide = JOptionPane.showInputDialog("Enter 'English' for Morse to English code translation and 'Morse' for English to Morse code translation.Pay attention to Caps.");

        //Enter String
        String phrasep = JOptionPane.showInputDialog("Enter the words you wish to translate.");

        if ( decide.equals( s1 ))
            toMorse( phrasep );

        else
            toEnglish( phrasep );

    }

    // Translate to Morse
    public static void toMorse( String phrase1 )
    {
        char[] english = new char[36];
        char[] number = { 1 };

        for (  int i = 65, j = 0; i < 91; i++, j++)
        {
            english[j] = (char)i;
        }


        english[26] = 1;
        english[27] = 2;
        english[28] = 3;
        english[29] = 4;
        english[30] = 5;
        english[31] = 6;
        english[32] = 7;
        english[33] = 8;
        english[34] = 9;
        english[35] = 0;

        String[] morse = new String[36];

        morse[0] =  " .- ";
        morse[1] =  " -.. ";
        morse[2] =  " -.-. ";
        morse[3] =  " -.. ";
        morse[4] =  " . ";
        morse[5] =  " ..-. ";
        morse[6] =  " --. ";
        morse[7] =  " .... ";
        morse[8] =  " .. ";
        morse[9] =  " .--- ";
        morse[10] =  " -.- ";
        morse[11] =  " .-.. ";
        morse[12] =  " -- ";
        morse[13] =  " -." ;
        morse[14] =  " --- ";
        morse[15] =  " .--. ";
        morse[16] =  " --.- ";
        morse[17] =  " .-. ";
        morse[18] =  " ... ";
        morse[19] =  " - ";
        morse[20] =  " ..- ";
        morse[21] =  " ...- ";
        morse[22] =  " .-- ";
        morse[23] =  " -..- ";
        morse[24] =  " -.-- ";
        morse[25] =  " --.. ";
        morse[26] =  " .---- ";
        morse[27] =  " ..--- ";
        morse[28] =  " ...-- ";
        morse[29] =  " ....- ";
        morse[30] =  " ..... ";
        morse[31] =  " -.... ";
        morse[32] =  " --... ";
        morse[33] =  " ---.. ";
        morse[34] =  " ----. ";
        morse[35] =  " ----- ";

        String phrase = phrase1.replace( "//s+", "|");

        String[] translation = new String[phrase1.length()];

        for ( int j = 0, t = 0, n = 1; j < phrase.length(); j++)
        {
            while ( j < phrase.length() )
            {
                if ( phrase.substring(t, n ).equals ( english[j] ) )
                {
                    translation[t] = morse[j];
                    t++;
                    n++;
                }
            }
        }
    System.out.println( translation );
    }

    public static void toEnglish( String phrase)
    {
        System.out.println( phrase );
    }
}
  • 1 1 Answer
  • 0 Views
  • 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-06-09T16:23:57+00:00Added an answer on June 9, 2026 at 4:23 pm

    Your code has an infinite loop in it.

    Look at the variable J. You set the variable in a for/next loop, but then you test the variable in a while loop. Every time it finishes the while loop it tests to see if j < phrase.length(). But since J doesn’t change until you LEAVE the while loop, it will never leave.

    You don’t need this test twice. Remove the while, let the for loop take care of it.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

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.