茵茵今年已经六年级了,爸爸给她报了一个学习程序设计的班。
第一节课上,老师讲的就是如何输入一个数,再原样输出出来。
以现在的你看来,挺容易的是不?
那么,就请你也写出一个一样的程序吧
输入
第一行是一个整数N(N<10)表示测试数据的组数)
接下来的n行 每行只有一个数(可能是小数,也可能是整数)
这个数的位数(整数位数+小数位数)不超过19位
输出
原样输出每个数,每输出占一行
5 个解决方案
#1
将数字转化为字符串之后输出
#2
能写出来么?
#3
请问你不知道类型怎么读数字?
就算能读数字也会因为二进制浮点数出问题,反而不对
直接读字符串写字符串最好
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int c=scanner.nextInt();
scanner.nextLine();
String[] lines=new String[c];
int i=0;
while (i<c) {
lines[i++]=scanner.nextLine();
}
for (i=0; i<c; i++) {
System.out.println(lines[i]);
}
scanner.close();
}
#4
错误信息如下:
./UserSrc/Main.java:1: class, interface, or enum expected
public static void main(String[] args) {
^
./UserSrc/Main.java:3: class, interface, or enum expected
int c=scanner.nextInt();
^
./UserSrc/Main.java:4: class, interface, or enum expected
scanner.nextLine();
^
./UserSrc/Main.java:5: class, interface, or enum expected
String[] lines=new String[c];
^
./UserSrc/Main.java:6: class, interface, or enum expected
int i=0;
^
./UserSrc/Main.java:7: class, interface, or enum expected
while (i<c) {
^
./UserSrc/Main.java:9: class, interface, or enum expected
}
^
./UserSrc/Main.java:10: class, interface, or enum expected
for (i=0; i<c; i++) {
^
./UserSrc/Main.java:10: class, interface, or enum expected
for (i=0; i<c; i++) {
^
./UserSrc/Main.java:12: class, interface, or enum expected
}
^
./UserSrc/Main.java:14: class, interface, or enum expected
}
^
11 errors
./UserSrc/Main.java:1: class, interface, or enum expected
public static void main(String[] args) {
^
./UserSrc/Main.java:3: class, interface, or enum expected
int c=scanner.nextInt();
^
./UserSrc/Main.java:4: class, interface, or enum expected
scanner.nextLine();
^
./UserSrc/Main.java:5: class, interface, or enum expected
String[] lines=new String[c];
^
./UserSrc/Main.java:6: class, interface, or enum expected
int i=0;
^
./UserSrc/Main.java:7: class, interface, or enum expected
while (i<c) {
^
./UserSrc/Main.java:9: class, interface, or enum expected
}
^
./UserSrc/Main.java:10: class, interface, or enum expected
for (i=0; i<c; i++) {
^
./UserSrc/Main.java:10: class, interface, or enum expected
for (i=0; i<c; i++) {
^
./UserSrc/Main.java:12: class, interface, or enum expected
}
^
./UserSrc/Main.java:14: class, interface, or enum expected
}
^
11 errors
#5
你这肯定是直接原样复制过去的吧,人家代码只是写了一个main函数,没有写类名啊。
#1
将数字转化为字符串之后输出
#2
能写出来么?
#3
请问你不知道类型怎么读数字?
就算能读数字也会因为二进制浮点数出问题,反而不对
直接读字符串写字符串最好
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int c=scanner.nextInt();
scanner.nextLine();
String[] lines=new String[c];
int i=0;
while (i<c) {
lines[i++]=scanner.nextLine();
}
for (i=0; i<c; i++) {
System.out.println(lines[i]);
}
scanner.close();
}
#4
错误信息如下:
./UserSrc/Main.java:1: class, interface, or enum expected
public static void main(String[] args) {
^
./UserSrc/Main.java:3: class, interface, or enum expected
int c=scanner.nextInt();
^
./UserSrc/Main.java:4: class, interface, or enum expected
scanner.nextLine();
^
./UserSrc/Main.java:5: class, interface, or enum expected
String[] lines=new String[c];
^
./UserSrc/Main.java:6: class, interface, or enum expected
int i=0;
^
./UserSrc/Main.java:7: class, interface, or enum expected
while (i<c) {
^
./UserSrc/Main.java:9: class, interface, or enum expected
}
^
./UserSrc/Main.java:10: class, interface, or enum expected
for (i=0; i<c; i++) {
^
./UserSrc/Main.java:10: class, interface, or enum expected
for (i=0; i<c; i++) {
^
./UserSrc/Main.java:12: class, interface, or enum expected
}
^
./UserSrc/Main.java:14: class, interface, or enum expected
}
^
11 errors
./UserSrc/Main.java:1: class, interface, or enum expected
public static void main(String[] args) {
^
./UserSrc/Main.java:3: class, interface, or enum expected
int c=scanner.nextInt();
^
./UserSrc/Main.java:4: class, interface, or enum expected
scanner.nextLine();
^
./UserSrc/Main.java:5: class, interface, or enum expected
String[] lines=new String[c];
^
./UserSrc/Main.java:6: class, interface, or enum expected
int i=0;
^
./UserSrc/Main.java:7: class, interface, or enum expected
while (i<c) {
^
./UserSrc/Main.java:9: class, interface, or enum expected
}
^
./UserSrc/Main.java:10: class, interface, or enum expected
for (i=0; i<c; i++) {
^
./UserSrc/Main.java:10: class, interface, or enum expected
for (i=0; i<c; i++) {
^
./UserSrc/Main.java:12: class, interface, or enum expected
}
^
./UserSrc/Main.java:14: class, interface, or enum expected
}
^
11 errors
#5
你这肯定是直接原样复制过去的吧,人家代码只是写了一个main函数,没有写类名啊。