作者Sanbeishuu (三杯鼠)
看板java
标题[虫?] 请问这个原始码哪里有问题?
时间Fri Nov 2 00:53:50 2007
原始码
import java.util.Scanner;//class uses class Scanner
public class test
{
//main method begins
public static void main( String args[] )
{
//create scanner to obtain input
Scanner n;
n = new Scanner( System.in );
int n;//正方形边长
System.out.print( "请输入一个介於1到70的数值:" );//prompt
n = input.nextInt();//读取使用者输入的数值写到变数n
if ( 1<=n<=70 )//如果变数n介於1到70
i = 1;//将1写到变数i
while ( i<=n )//i小於n使用while loop
{
if ( i==1 || i==n )//如果i等於1或n
j = 1;//将1写到变数j
while ( j<=n )
{
System.out.print( "─" );//输出─
j = j + 1;//变数j加1
}
System.out.print( "\n" );//跳行
i = i + 1;
else
System.out.print( "│" );
j = 1;//将1写到变数j
while ( j<=n-2 )
{
System.out.print( " " );
j = j + 1;//变数j加1
}
System.out.print( "│\n" );
i = i + 1;
}
else
System.out.print( "错误!! 输入的数值未介於1到70" );
}
}
Microsoft Windows XP [版本 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\Administrator>d:
D:\>javac test.java
test.java:40: 'else' without 'if'
else
^
test.java:41: <identifier> expected
System.out.print( "│" );
^
test.java:41: illegal start of type
System.out.print( "│" );
^
test.java:43: <identifier> expected
j = 1;//将1写到变数j
^
test.java:45: illegal start of type
while ( j<=n-2 )
^
test.java:45: <identifier> expected
while ( j<=n-2 )
^
test.java:45: <identifier> expected
while ( j<=n-2 )
^
test.java:52: <identifier> expected
System.out.print( "│\n" );
^
test.java:52: illegal start of type
System.out.print( "│\n" );
^
test.java:54: <identifier> expected
i = i + 1;
^
test.java:57: class, interface, or enum expected
else
^
test.java:59: class, interface, or enum expected
}
^
12 errors
D:\>
compiler过不去 可是我也看不出来哪里有问题T.T
麻烦各位大大帮我看看
感谢
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.128.194.182
1F:推 TuTu522:if else 请加括号: if{...} else{...} 才不易搞错 11/02 00:56
2F:推 shaldrem:if else使用上的问题吧 结构上就有问题了 11/02 01:01
3F:推 Sanbeishuu:可是我刚刚把每个IF跟ELSE都加上 结果error更多了@@ 11/02 01:03
4F:→ Sanbeishuu:请问S大说得结构上就有问题是指? 11/02 01:03
5F:推 ton60316:if ( 1<=n<=70 ) 不是这样写XD 11/02 01:13
6F:推 ton60316:结构上也有问题... 11/02 01:16
7F:推 Sanbeishuu:啊...不可以这样写吗? 那那个if怎麽写呢? 11/02 01:19
8F:推 Sanbeishuu:结构上? 我把{}算的好好的 有20error 少打一个} 11/02 01:21
9F:→ Sanbeishuu:剩下一个error.... 这是啥咪情形.... 11/02 01:22
10F:推 buganini:找个好一点的editor看吧 11/02 02:32
11F:→ buganini:notepad++ or pspad 11/02 02:33
12F:推 icespeech:应该写if(n >= 1 && n <= 70) 11/02 04:00
13F:推 Sanbeishuu:嗯嗯 OK了 编译完成 运作也没有问题了 感谢各位大大 11/02 10:58
14F:→ Sanbeishuu:整个问题出在 前面没有定义变数i j.... 11/02 10:58
15F:→ Sanbeishuu:至於b大说的 教授规定先用记事本 恩 希望可以早点用 11/02 10:59
16F:→ Sanbeishuu:eclipse 不然整个就头很大XD 11/02 11:00
17F:推 MonyemLi:notepad++ or pspad 也是记事本的一种,提供语法高亮度 11/02 21:55
18F:推 slalala:双n?????????? 11/04 12:28
19F:推 PRAM:用记事本没啥不好啊 =__= 11/04 16:20
20F:推 Egriawei:emediter editplus也不错啊,关键字有颜色差别的ide就够了 11/04 21:48
21F:→ Egriawei:我倒觉得简单点的ide比较方便 11/04 21:49
22F:推 devc:Scanner物件怎麽宣告为n却又用input来呼叫方法? 11/14 00:18
23F:→ devc:i跟j也都没有宣告,怎麽使用? 11/14 00:20