Skip to main content
Rollback to Revision 1
Source Link
Mast
  • 13.8k
  • 12
  • 57
  • 127

I've been studying Java for some days and I'm just now starting to make some simple programs, I'd like to know if there's any 'noob' mistakes or habits that I could avoid.

In other words: how could my code be more streamlined to Java?

My code:

import java.util.Scanner;

public class Main
{
    private static String reverse_string(String my_string)
    {
        String reversed_string = "";
        for(int j = my_string.length() - 1; j >= 0; j--)
        {
            reversed_string +== reversed_string + my_string.charAt(j);
        }
        return reversed_string;
    }

    public static void main(String[] args)
    {
        System.out.print("Insert a 'String': ");

        Scanner input = new Scanner(System.in);
        String user_string = input.nextLine().toLowerCase().replace(" ", "");

        if (user_string.equals(reverse_string(user_string)))
            {
                System.out.println("It is a palindrome.");
            } else
            {
                System.out.println("It is not a palindrome.");
            }
    }
}

I believe there are already other alternatives to my reverse_string function, hence the 'reinventing the wheel' tag.

I've been studying Java for some days and I'm just now starting to make some simple programs, I'd like to know if there's any 'noob' mistakes or habits that I could avoid.

In other words: how could my code be more streamlined to Java?

My code:

import java.util.Scanner;

public class Main
{
    private static String reverse_string(String my_string)
    {
        String reversed_string = "";
        for(int j = my_string.length() - 1; j >= 0; j--)
        {
            reversed_string += my_string.charAt(j);
        }
        return reversed_string;
    }

    public static void main(String[] args)
    {
        System.out.print("Insert a 'String': ");

        Scanner input = new Scanner(System.in);
        String user_string = input.nextLine().toLowerCase().replace(" ", "");

        if (user_string.equals(reverse_string(user_string)))
            {
                System.out.println("It is a palindrome.");
            } else
            {
                System.out.println("It is not a palindrome.");
            }
    }
}

I believe there are already other alternatives to my reverse_string function, hence the 'reinventing the wheel' tag.

I've been studying Java for some days and I'm just now starting to make some simple programs, I'd like to know if there's any 'noob' mistakes or habits that I could avoid.

In other words: how could my code be more streamlined to Java?

My code:

import java.util.Scanner;

public class Main
{
    private static String reverse_string(String my_string)
    {
        String reversed_string = "";
        for(int j = my_string.length() - 1; j >= 0; j--)
        {
            reversed_string = reversed_string + my_string.charAt(j);
        }
        return reversed_string;
    }

    public static void main(String[] args)
    {
        System.out.print("Insert a 'String': ");

        Scanner input = new Scanner(System.in);
        String user_string = input.nextLine().toLowerCase().replace(" ", "");

        if (user_string.equals(reverse_string(user_string)))
            {
                System.out.println("It is a palindrome.");
            } else
            {
                System.out.println("It is not a palindrome.");
            }
    }
}

I believe there are already other alternatives to my reverse_string function, hence the 'reinventing the wheel' tag.

deleted 17 characters in body
Source Link
Tlomoloko
  • 635
  • 7
  • 20

I've been studying Java for some days and I'm just now starting to make some simple programs, I'd like to know if there's any 'noob' mistakes or habits that I could avoid.

In other words: how could my code be more streamlined to Java?

My code:

import java.util.Scanner;

public class Main
{
    private static String reverse_string(String my_string)
    {
        String reversed_string = "";
        for(int j = my_string.length() - 1; j >= 0; j--)
        {
            reversed_string = reversed_string ++= my_string.charAt(j);
        }
        return reversed_string;
    }

    public static void main(String[] args)
    {
        System.out.print("Insert a 'String': ");

        Scanner input = new Scanner(System.in);
        String user_string = input.nextLine().toLowerCase().replace(" ", "");

        if (user_string.equals(reverse_string(user_string)))
            {
                System.out.println("It is a palindrome.");
            } else
            {
                System.out.println("It is not a palindrome.");
            }
    }
}

I believe there are already other alternatives to my reverse_string function, hence the 'reinventing the wheel' tag.

I've been studying Java for some days and I'm just now starting to make some simple programs, I'd like to know if there's any 'noob' mistakes or habits that I could avoid.

In other words: how could my code be more streamlined to Java?

My code:

import java.util.Scanner;

public class Main
{
    private static String reverse_string(String my_string)
    {
        String reversed_string = "";
        for(int j = my_string.length() - 1; j >= 0; j--)
        {
            reversed_string = reversed_string + my_string.charAt(j);
        }
        return reversed_string;
    }

    public static void main(String[] args)
    {
        System.out.print("Insert a 'String': ");

        Scanner input = new Scanner(System.in);
        String user_string = input.nextLine().toLowerCase().replace(" ", "");

        if (user_string.equals(reverse_string(user_string)))
            {
                System.out.println("It is a palindrome.");
            } else
            {
                System.out.println("It is not a palindrome.");
            }
    }
}

I believe there are already other alternatives to my reverse_string function, hence the 'reinventing the wheel' tag.

I've been studying Java for some days and I'm just now starting to make some simple programs, I'd like to know if there's any 'noob' mistakes or habits that I could avoid.

In other words: how could my code be more streamlined to Java?

My code:

import java.util.Scanner;

public class Main
{
    private static String reverse_string(String my_string)
    {
        String reversed_string = "";
        for(int j = my_string.length() - 1; j >= 0; j--)
        {
            reversed_string += my_string.charAt(j);
        }
        return reversed_string;
    }

    public static void main(String[] args)
    {
        System.out.print("Insert a 'String': ");

        Scanner input = new Scanner(System.in);
        String user_string = input.nextLine().toLowerCase().replace(" ", "");

        if (user_string.equals(reverse_string(user_string)))
            {
                System.out.println("It is a palindrome.");
            } else
            {
                System.out.println("It is not a palindrome.");
            }
    }
}

I believe there are already other alternatives to my reverse_string function, hence the 'reinventing the wheel' tag.

Became Hot Network Question
Tweeted twitter.com/StackCodeReview/status/1230009118905307136
Source Link
Tlomoloko
  • 635
  • 7
  • 20

Palindrome checker program

I've been studying Java for some days and I'm just now starting to make some simple programs, I'd like to know if there's any 'noob' mistakes or habits that I could avoid.

In other words: how could my code be more streamlined to Java?

My code:

import java.util.Scanner;

public class Main
{
    private static String reverse_string(String my_string)
    {
        String reversed_string = "";
        for(int j = my_string.length() - 1; j >= 0; j--)
        {
            reversed_string = reversed_string + my_string.charAt(j);
        }
        return reversed_string;
    }

    public static void main(String[] args)
    {
        System.out.print("Insert a 'String': ");

        Scanner input = new Scanner(System.in);
        String user_string = input.nextLine().toLowerCase().replace(" ", "");

        if (user_string.equals(reverse_string(user_string)))
            {
                System.out.println("It is a palindrome.");
            } else
            {
                System.out.println("It is not a palindrome.");
            }
    }
}

I believe there are already other alternatives to my reverse_string function, hence the 'reinventing the wheel' tag.