Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

求大牛改正Java代码! 本人属新手,望得到指点!(runtime error)

Posted by sdau10_xiaolong at 2011-03-13 16:53:33 on Problem 1028
import java.util.Scanner ;

public class poj1028{

	static String str[] = new String[100] ;

	static int i = 1 ;
	public static void main(String args[]){
		for(int x=0; x<100; x++)
			str[x] = null ;
		str [1] = "http://www.acm.org/" ;
		Scanner sc = new Scanner(System.in) ;
		for(;;){
			String demo = sc.nextLine() ;
			char d = demo.charAt(0) ;
			switch (d){
				case 'V':{
					visit() ;
					break ;
				}
				case 'B':{
					back() ;
					break ;
				}
				case 'F':{
					forward() ;
					break ;
				}
				case 'Q':{
					System.exit(1) ;
					break ;
				}
			}
		}
	}
	static void visit(){
		Scanner sc = new Scanner(System.in) ;
		i ++ ;
		str[i] = sc.nextLine() ;
		System.out.println(str[i]) ;
	}
	static void back(){
		i -- ;
		if(str[i]==null){
			System.out.println("Ignored") ;
			i ++ ;
		}
		else
			System.out.println(str[i]) ;
	}
	static void forward(){
		i ++ ;
		if(str[i]==null){
			System.out.println("Ignored") ;
			i -- ;
		}
		else
			System.out.println(str[i]) ;
	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator