作者liyard (Keyword)
看板java
标题Re: [问题] 新手一问 关於语法
时间Thu Mar 5 00:18:44 2009
※ 引述《NOtWorThy (骇客技术去哪学?)》之铭言:
: 1.
: import java.util.Scanner;
: public class New
: {
: public static void main(String args[ ])
: {
: Scanner scanner = new Scanner(System.in);
: System.out.printf("Hello!!") ;
: System.out.println();
: System.out.printf("enter a number:");
: System.out.printf("Oh! I get a number %d!!\n", scanner.nextInt());
: System.out.println("You are ?");
: System.out.printf("Hello, %s\n", scanner.next());
: }
: }
: /* JAVA中似乎再让使用者输入前不需宣告变数及形态,那如此他要如何知道我
: 输入多少变数? 如:在enter a number:後面我输入整数玩在输入字元字串在输入浮点数
: ...,他要如何记忆??如果我输入两次整数那下一行输出结果要输出哪个呢?*/
听不太懂...
如果你是希望一次输入一串 ex: 3 2.5 8
那你要做的应该是拿到一整个字串,再处理把三个数分开
如果你是希望他要求输入多次,那就用回圈
如果你只是要「记忆」,那就存起来
int i = scanner.nextInt();
String s = scanner.next();
: 2.
: import java.io.*;
: public class New {
: public static void main(String[] args) throws IOException
: {
: BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
: /* 上面这行是类似C的别名吗?还是?? */
我觉得可以理解为用BufferedReader「包装」
宣告BufferedReader物件
: System.out.print("请输入一列文字: ");
: String text = buf.readLine(); /* 看不懂 ~"~ */
^^ ^^^^^^^^^^^
存入text 读取输入字串
: System.out.println("您输入的文字: " + text); /*位什麽是+?? */
+是连结两个字串的符号
: }
: }
: 抱歉我是新手
: 没书
: 只有在网路上自学
: 但是他的范例中 很多都没讲原因 跟做注解
: 所以学起来雾煞煞
: 烦请高手不吝解析
: 谢谢
我不是高手,只是新手,所以有错麻烦指正
建议你还是去买本书吧,光从网路上要学到系统化的入门知识还是有点困难的
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.44.21.76
1F:推 NOtWorThy:太感激了 谢谢~ 03/05 00:22