我正在做一个项目,需要用户输入7个信息元素(全部一次,用逗号分隔)。如果输入了任何无效字段,则显示一条消息并要求用户再次输入该字段。如果所有的信息。输入正确。显示所有字段,每行一个字段带标签。到目前为止,我得到的是:
import java.util.Scanner;
public class Implementation
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.println("P
我正在编写一个程序,其中用户输入他们的名字和姓氏之间的空格在一行。然后,该程序将检测空间,并将名字和姓氏提取到不同的变量中,以便打印出来。
例如:假设一个用户在一行中输入了"simon“,中间有空格,我希望它像这样输出:Forename: Simon姓氏: Hall
我的代码(现在几乎没用):(下面是输入/输出)
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Sys
我正在尝试为类创建一个程序,当用户输入系数时,该程序计算给定方程的判别式。不过,我在将输入从字符串转换为int时遇到了问题。我的老师一心想要确保我让用户在一行中输入所有的系数,这就是问题所在。 到目前为止,我的代码如下: /*
* Write a program that will determine the number and type of roots
* for a quadratic equation, given the coefficients a, b, and c.
*/
import java.util.Scanner;
public class Main
{
我试图从用户那里获得文件名的输入,然后进行所有的计算。但它一直返回给我一个错误。该文件存在于同一目录中。
import java.io.*;
import java.util.*;
public class test{
public static void main(String args[]) throws FileNotFoundException {
//File fin = new File ("matrix1.txt");
Scanner scanner = new Scanner(System.in);
scanner.nextLine(); // removes
我试图为我的项目编写一个简单的代码,如果用户输入
步行10
我需要在步行(距离)方法中使用“步行”命令,因为距离= 10,我有类似的东西
while (!quit) {
Scanner in = new Scanner(System.in);
String input = in.nextLine();
// if (walk x is typed) {
walk(x);
}
}
我使用的是java.util.scanner,另一个问题是我的方法walk(int )使用int,所以我需要将字符串输入转换为int
我在网上搜索了一段时间,但找不到我要找的东西(或者我不明白)
所以不管怎么说,如果
这是我应该得到的。
样本输出:
Please enter the coordinates in a clockwise order.
Enter the GPS coordinates for the 1st city: 35.2270869 -80.8431267
Enter the GPS coordinates for the 2nd city: 32.0835407 -81.0998342
Enter the GPS coordinates for the 3rd city: 28.5383355 -81.3792365
Enter the GPS co
我一直在尝试这个程序。但我没有得到所需的输出。
导入java.util.*;
class MiscTest {
public static void main(String[] args) {
int i = 10;
double d = 4.0;
String s = "Lavante ";
Scanner scanner = new Scanner(System.in);
int j;
double dd;
String ss;
我目前正在努力编写一个使用java的程序。目前程序都是好的。然而,我犯了一个小错误。对于情况1(添加项目),我尝试在制造商中键入带空格的字符串。在Eclipse中会出现这样的错误
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextDouble(Unknown Source)
at ass