3 回答
TA贡献1890条经验 获得超9个赞
还是一样。
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner kbd = new Scanner(System.in);
System.out.print("Word:");
String s = kbd.nextLine();
System.out.println("Input:" +s); // print the string
System.out.println("Length:" + s.length()); // the length of the string
}
}
TA贡献1812条经验 获得超5个赞
我不明白你想要什么。
import java.util.Scanner;
public class lab
{
public static void main(String[] args)
{
Scanner kbd = new Scanner(System.in);
System.out.print("1st string: ");
String s = kbd.nextLine();
System.out.print("2nd string: ");
String s1 = kbd.nextLine();
System.out.println(s.length()); // this is for the length
System.out.println(s1); // this if for the input only
}
}
TA贡献1111条经验 获得超0个赞
import java.util.Scanner;
public class lab {
public static void main(String [] args)
{
Scanner kbd = new Scanner(System.in);
String s = kbd.next();
String s1 = kbd.nextLine();
System.out.println(s.length());
System.out.println(s);
System.out.println(s1);
}
}
Scanner没有lenght(),Length()方法仅适用于字符串变量
您使用哪个 IDE(Eclipse、Netbeans、Intellij?),因为 IDE 通常会向您显示错误
添加回答
举报