Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 需要了解如何在数组中一次转换一个字符值_Java_Arrays_Methods_Rot13 - Fatal编程技术网

Java 需要了解如何在数组中一次转换一个字符值

Java 需要了解如何在数组中一次转换一个字符值,java,arrays,methods,rot13,Java,Arrays,Methods,Rot13,我已经编写了将用户的字符串值引入数组的代码。我还写了把这些打印出来的代码 我遇到的问题是理解如何从可用字符串数组中给方法charConvert()一个char值,并让它转换该字符,然后替换字符串数组中的字符 import java.util.Scanner; public class zrwilliams_ROT13Arrays { private static Scanner get = new Scanner ( System.in ); public static vo

我已经编写了将用户的字符串值引入数组的代码。我还写了把这些打印出来的代码

我遇到的问题是理解如何从可用字符串数组中给方法
charConvert()
一个char值,并让它转换该字符,然后替换字符串数组中的字符

import java.util.Scanner;

public class zrwilliams_ROT13Arrays {
    private static Scanner get = new Scanner ( System.in );

    public static void main ( String args[] ){

        String[] sentences = new String[5];
        getSentences ( sentences );
        displayOriginal ( sentences );

        charConvert( );

        for ( char temp = 'A'; temp <= 'Z'; temp++ ) {
            System.out.printf ( "%c converts to %c\n", temp, charConvert(temp));
        }

    }
    /**
     * getSentences
     *
     * This method allows the user to enter text into each of the
     * element of the String array that it receives.
     *
     * @param sentences An array of String[] data
     * @return None
     */
    public static void getSentences ( String[] sent ) {

        System.out.println ( "Enter your 5 sentences below: " );
        System.out.print ( "\n" );

        int a = 1;

        for ( int x = 0 ; x < sent.length; x++ ) {


            System.out.printf ( "Sentence %d> ", a );
            sent[x] = get.nextLine();
            a = a + 1;

        }
    }
    /**
     * displayOriginal
     *
     * This method displays all of the elements of the array of
     * String data that it receives, line by line (element by element).
     *
     * @param sentences An array of String[] data
     * @return None
     */
    public static void displayOriginal ( String[] sent ) {

        System.out.print ( "\nThe original text: \n" );

        for ( int x = 0; x < sent.length; x++ ) {
            System.out.println ( sent[x] );
        }
    }
    /**
     * charConvert
     d     *
     * This method will take one char value as a parameter and convert
     * it to its appropriate ROT13 equivalent. The return value will be the
     * new ROT13 char equivalent.
     *
     * This method will not do any output.
     *
     * @param toConvert A character to convert as a char
     * @return The new ROT13 equivalent value as a char
     */
    public static void charConvert ( String[] sent  ) {

    }
    /**
     * convertSentence
     *
     * This method will do the actual conversion of a String of data to its
     * ROT13 equivalent in 5-character chunks of data. It should call on
     * the charConvert() method to do the actual character conversion for each
     * individual character. In other words, individual character conversion
     * should not happen within this method.
     *
     * This method will not do any output.
     *
     * @param sentence A String variable to convert
     * @return The 5-characters in a group ROT13 result as a String
     */
    public static void convertSentence ( String[] sent ) {

    }
    /**
     * displayROT13
     *
     * This method will display in ROT13 format all of the elements of the
     * array of String data that it receives . It will need to call on the
     * method convertSentence() to convert each string before it displays it.
     * Note that the original array should not be modified with ROT13 data.
     *
     * @param sentences An array of String[] data
     * @return None
     */
    public static void displayROT13 ( String[] sent ) {

    }
    /**
     * displayCombinedROT13
     *
     * This method takes an array of String data and combines all of the Strings
     * into a single String that is then processed by the convertSentence()
     * method. The method should essentially display the same results as the
     * displayROT13() method, except that there won't be separate lines of
     * output but rather one large result instead.
     *
     * @param sentences An array of String[] data
     * @return None
     */
    public static void displayCombinedROT13 ( String[] sent ) {

    }
}
import java.util.Scanner;
公共类ZRU ROT13阵列{
专用静态扫描仪get=新扫描仪(System.in);
公共静态void main(字符串参数[]){
字符串[]句=新字符串[5];
句子;
显示原文(句子);
charConvert();

for(char temp='A';temp有什么问题?我不知道如何一次将字符串中的一个字符值发送到方法。我不需要为我编写代码。只需解释一下如何执行该操作可能会非常有用。一般来说:首先需要从数组中检索值,并将其用作方法的参数(在那个教程中没有解释,但你还是应该读一读)。一个相当一般的例子如下:
some_方法(array[index])
使用指定索引处的数组元素调用
some_方法
。尝试将其转换为Charray并选择需要重新运行的字符char或string,类似的操作可能会帮助您:
string testString=“this Is Test”;char[]StringToCharray=testString.ToCharray();例如(字符输出:StringToCharray){System.out.println(输出);}
谢谢Paul!现在,如果我想循环遍历数组中的所有值,我是否应该创建一个for循环,使其命中每个值?问题是什么?我不知道如何一次将字符串中的一个字符值发送到方法。我不需要为我编写代码。只是解释一下如何执行该操作可能会非常有用。一般来说:您首先需要从数组中检索值,并将其用作方法的参数(该教程中没有解释,但您仍然应该对其进行阅读)
使用指定索引处的数组元素调用
some_方法
。尝试将其转换为Charray并选择需要重新运行的字符char或string,类似的操作可能会帮助您:
string testString=“this Is Test”;char[]StringToCharray=testString.ToCharray();例如(char output:StringToCharray){System.out.println(output);}
谢谢Paul!现在如果我想循环数组中的所有值,我是否应该创建一个for循环,让它命中每个值?