Возникли проблемы с группировкой строк в определенные группы - PullRequest
0 голосов
/ 19 февраля 2019

Я пишу программу, которая требует от пользователя ввода строки, которая затем разбивается на группы кода, которые пользователь также вводит.например, программа спрашивает «Ввод текста, который вы хотите разделить на группы», ввод пользователя «Гарольд», а затем «Сколько групп вы хотите разбить на это?»пользовательский ввод "3", так что пользовательский ввод "Harold, 3" должен возвращать "Har old" код ниже, который O написал, только разделяет введенную строку на одиночные пробелы и не группирует данные в строке в указанную кодовую группу, которая являетсявводится пользователем.

   import java.util.*;

  public class Main {

   public static void main (String[] args) {
 //        normalizeText();
 //        obify( "THISISSOMEREALLYGREATTEXT" );
 //        caesarify( "", 3 );
    //text = ask the user for the test
    //size = as the user for the size of each chunk
    groupify( "", 0, "" );


}

// Part 1 Normalized Method to convert all letter to uppercase and 
enter code hereremoving all special characters and placing it into String codey.
public static String normalizeText ( ) {
    Scanner sc = new Scanner( System.in );
    String normText;

    System.out.println( "Please input text to encrypt" );
    normText = sc.nextLine();

    System.out.println( normText.replaceAll( " ", "" ).replaceAll( "[^a-zA-Z ]", "" ).toUpperCase() );


    return normText;


}

//This method will take in the Normalized text and insert a capital O and 
B in-front of every vowel and return the text
private static String obify (String input) {

    String obifiledInput = "";
    char c;
    for (int i = 0; i < input.length(); i++) {
        c = input.charAt( i );
        if (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U' || c == 'Y') {
            obifiledInput += "OB";
        }
        obifiledInput += c;
    }
    System.out.println( obifiledInput );
    return obifiledInput;
}


//  Part 3 Method Caesarify that shifts each individual character by 
certain number key*//
private static String caesarify (String c, int shift) {
    Scanner sc = new Scanner( System.in );
    String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    String result = "";

    System.out.println( "Enter the text you wish to encrypt" );
    c = sc.nextLine();
    System.out.println( "Enter a number how many places you wish to shift 
 your text up and down the alphabet" );
    shift = sc.nextInt();

    for (int counter = 0; counter < c.length(); counter++) {
        char v = c.charAt( counter );
        int i = alphabet.indexOf( v );
        int f = i + shift;
        if (f >= 0) {
            if (f > 25) {
                while (f > 25) {
                    f -= 26;
                }
            }
        } else {
            while (f < 0) {
                f += 26;
            }
        }
        result = result + alphabet.charAt( f );
    }
    return result;
}

// This method should break a String up into parts whose length is 
determined by the integer.
// The last parse should be padded with 'x' to fill the segment length.
public static String groupify (String theTest, int lengthOfEachChunck, 
String text) {
    Scanner sc = new Scanner( System.in );
    String result = "";
    System.out.println( "Input text you wish to separate into groups" );
    theTest = sc.nextLine();
    System.out.println( "How many groups do you wish to break this up 
into?" );
    lengthOfEachChunck = sc.nextInt();
    StringBuffer sbSpace = new StringBuffer();
    for (int i = 0; i <= lengthOfEachChunck; i++) {
        sbSpace.append( " ");
    }

    char[] letter = theTest.toCharArray();
    for (int i = 0; i < letter.length; i++) {`enter code here`
        String str = String.valueOf( sbSpace );
        result = str + letter[i];
        System.out.print( result);

    }

    return result;
}

}

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...