>codeshame
Score: 4.2 out of 10
4.2/10
public roast
verdict: could_be_worse
Java
41 lines
3 focus points

"Clumsy string manipulation disaster"

Here is the breakdown of what hurt your score, plus a cleaned-up version you can use as a starting point. If the roast feels fair, share it. If it feels unfair, paste better code next time.

score

4.2 / 10

fixed output

24 lines

line delta

-17

// summary

Your strongest next move is to fix the highest-severity issue first, then compare the cleanup against the original before shipping anything.

// sharing

Public roasts can land in the leaderboard. Private reviews stay out of it and are better for real code you do not want exposed.

// compare

Use the original and fixed blocks below to spot naming, logic, and structure changes quickly instead of reading the whole thing twice.

//your_submission
TextTorturer.java

import java.util.Scanner;

public class ManipuladordeTexto {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.println("Insira um bloco de texto:");
        String texto = scanner.nextLine();

        String textoSemEspacos = texto.trim();
        System.out.println("Texto com trim(): " + textoSemEspacos);

        if (textoSemEspacos.length() >= 5) {
            String parte = textoSemEspacos.substring(0, 5);
            System.out.println("substring(0,5): " + parte);
        } else {
            System.out.println("texto muito curto para usar substring(0,5).");
        }

        String textoSubstituido = textoSemEspacos.replace("a", "@");
        System.out.println("replace('a','@'): " + textoSubstituido);

        System.out.println("toUpperCase(): " + textoSemEspacos.toUpperCase());

        System.out.println("toLowerCase(): " + textoSemEspacos.toLowerCase());

        String[] palavras = textoSemEspacos.split(" ");
        System.out.println("Palavras separadas com split():");
        for (String palavra : palavras) {
            System.out.println(palavra);
        }

        int numero = 2026;
        String numeroConvertido = String.valueOf(numero);
        System.out.println("String.valueOf(numero): " + numeroConvertido);

    }
}

//detailed_analysis
!

Inefficient Input Handling

Using `nextLine()` without checking for `EOF` or `IOException` is a rookie mistake. What if the user decides to Ctrl+D out of frustration?
?

Magic Numbers

Hardcoding numbers like 5 in `substring(0, 5)` is not only lazy but also makes the code inflexible. What if we need to change it to 10?
+

Inconsistent Formatting

Using both `String.valueOf()` and `Integer.toString()` to convert numbers to strings is inconsistent and confusing. Pick one and stick to it, or use a better method like `String.format()`
//suggested_fix

original: 41 lines · fixed: 24 lines

TextTorturer_fixed.java
+import java.util.Scanner;
+public class TextTorturer {
+ public static void main(String[] args) {
+ Scanner scanner = new Scanner(System.in);
+ System.out.println("Enter text:");
+ String input = scanner.nextLine().trim();
+ System.out.println("Trimmed text: " + input);
+ if (input.length() >= 5) {
+ System.out.println("First 5 chars: " + input.substring(0, 5));
+ } else {
+ System.out.println("Text too short");
+ }
+ System.out.println("Replaced 'a' with '@': " + input.replace("a", "@"));
+ System.out.println("Upper case: " + input.toUpperCase());
+ System.out.println("Lower case: " + input.toLowerCase());
+ String[] words = input.split(" ");
+ System.out.println("Words:");
+ for (String word : words) {
+ System.out.println(word);
+ }
+ int number = 2026;
+ System.out.println("Number as string: " + Integer.toString(number));
+ }
+}