Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.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 我需要有人帮我弄清楚如何模仿一个人;s响应连续100次_Java - Fatal编程技术网

Java 我需要有人帮我弄清楚如何模仿一个人;s响应连续100次

Java 我需要有人帮我弄清楚如何模仿一个人;s响应连续100次,java,Java,我不是在寻找直接的答案。我只是想知道我想要的东西是否可以通过我开始的方式实现,以及我如何开始尝试类似的东西。将名称输入作为字符串,并使用for循环打印它。我希望我不是太直接。您需要声明一个用于保存用户输入的。然后,您可以使用a来执行任意次数的操作 import java.util.Scanner; // *Has to be outside of brackets!* public class Lab_1_3_Class_oops { public static void main(

我不是在寻找直接的答案。我只是想知道我想要的东西是否可以通过我开始的方式实现,以及我如何开始尝试类似的东西。

将名称输入作为字符串,并使用for循环打印它。我希望我不是太直接。

您需要声明一个用于保存用户输入的。然后,您可以使用a来执行任意次数的操作

import java.util.Scanner; // *Has to be outside of brackets!*

public class Lab_1_3_Class_oops {

    public static void main(String[] args) {

        //I need to request a person's first and last name, then copy it on individual lines after they have entered their input
        //Variables
        Scanner sc = new Scanner(System.in);

        //Requesting a name
        System.out.print("Please write your first and last name.\n");

        //Allowing a name input
        sc.nextLine();

        //I get as far as allowing text to be entered, but I can't figure out a way to keep that text in the memory long enough to get it copied 100 times without making the person type it 100 times
    }
}
String name=sc.nextLine();//声明一个字符串变量来保存该值
for(int i=0;i<1337;i++){//使用for循环
//做点什么
}

声明a保存用户输入,然后将其放入a(从那里打印)

非常感谢大家!我是通过声明

String name = sc.nextLine(); // Declare a String variable to hold the value
for(int i = 0; i < 1337; i++) { // Use a for loop
    // do something
}
然后创建一个while循环

int num = 1;

while(num)您需要将输入分配给一个变量。我假设sc.nextLine返回一个字符串,因此您需要一个字符串变量来分配该返回值。
string personName=sc.nextLine();
现在它存储在内存中。现在查找
while
循环,将其打印100次。这就是我能为您提供的全部帮助,否则我会伤害您。您必须声明变量
字符串s;
,使用
s=sc.nextLine()使其可读
你应该通过阅读一些基础书籍或教程来创建一个数组或数组列表,在其中你可以打印每个位置的值(因此声明一个
int pos=0
,并使用
来打印它)标签毫无意义。我会使用
while
循环,因为在学习编程时更容易理解,但是那些指向文档的链接很有用,尽管我至少会展示变量是如何创建到您的answer@Jelliebean71请使用标记作为答案,以防止人们在未回答的问题中访问此论坛
while (num <= 100) {
        System.out.println(name);
        num = num + 1;
    }