2017-03-11 1 views
1

초보자 용의 질문에 대해 유감이지만이 사실을 알 수는 없습니다. 이 코드를 시작할 때 불법적 인 시작 표현 오류가 발생하며 그 이유를 알 수 없습니다. 어떤 도움을 주셔서 감사합니다. 여기 불법적 인 표현식 시작 public int getInput

public int getInput(int length){ 
    System.out.println("Enter an index of your choice:"); 
    Scanner input = new Scanner(System.in); 
    choice = input.nextInt(); 
    if(choice > length){ 
     System.out.println("The number is out of the array bound"); 
    } 
    return choice; 
} 

import java.util.Random; 
import java.util.Scanner; 


public class shoutboxclasswithmethods { 

//Tell the system about varibles and activate 
int a = 0, i = 0, choice; 


/** 
* @param args the command line arguments 
*/ 
public static void main(String[] args) { 
    // TODO code application logic here 

public int getInput(int length){ 
    System.out.println("Enter an index of your choice:"); 
    Scanner input = new Scanner(System.in); 
    choice = input.nextInt(); 


    if(choice > length){ 
     System.out.println("The number is out of the array bound"); 
    } 
    return choice; 
} 

/* 
* display all the array content 
* @returns a string as per user slected index 
*/ 
public String ShoutOutCannedMessage() { 
//declare and intialize the array with ten messages 
    String[] cannedMessage = {"Hello", "this", "is","a test","for","my", 
     "homework","Hello World","I love Java","Welcome","Thank you"}; 
    //get the lenght of the array 
    i = cannedMessage.length; 
    //display using the loop limiting the loop to only the number of array index+1 
    for (; a < i; a++) { 
     System.out.println("Index " + a + " : " +cannedMessage[a]); 
    } 
    //get the user input of an index using the getInput() predefined user method 
      int y = getInput(i); 
      //select and assign the message at the index to a string variable 
    String selectedMessage = cannedMessage[y]; 
//return the string varibale object 
    return selectedMessage; 
}  
/* generate a random number within a limit 
* returns a string from five string arrays choosen depending on the random number as an index 
*/ 

public String ShoutOutRandomMessage(){ 
    //declare and intialize the arrays 
    String [] subject={"You","She","It","They","We","He","Who","Which","Is","I"}; 
    String [] verb={"read","breathe","run","draw","study","shake","eat","talk","write","show"}; 
    String [] adjective={"funny", "prickly","hard","peaceful","confident","loud","qualified","wealthy","wrong","academic"}; 
    String [] object={"Java","Jane","course","homework","paper","Fish","Key", "phone","prince","laptop"}; 
    String [] adverb={"daily","equally","easily","beautifully","calmly","closely","thankfully","regularly","always","quickly"}; 

    //generate a rando number with upper bound of 10 
    Random rand=new Random(); 
    choice=rand.nextInt(10); 
    //select and assign the message content to a single string 
    String r= subject[choice] +" "+verb[choice]+" "+adjective[choice]+" "+object[choice]+" "+adverb[choice]+"."; 
    //return the string 
    return r; 

} 

} 
+0

자체는 괜찮 방법, 가정'choice' 어딘가 범위 선언 : 여기

오류의 유형을 해결하기 위해 몇 가지 팁을 줄 것이다 링크입니다. 아마도 클래스 외부 나 다른 메소드 내부와 같이 불법적으로 정의 된 클래스 일 수 있습니다. 코드를 둘러싼 코드를 보지 않고도 말하기는 불가능합니다. – azurefrog

+0

빠른 답장을 보내 주셔서 감사합니다. 전체 코드를 포함하도록 내 게시물을 변경했습니다. – BDL427

답변

0

당신이 그것을 동봉되면) (주는

/** 
* @param args the command line arguments 
*/ 
public static void main(String[] args) { 
    // TODO code application logic here 

} 

폐쇄되지 않은 것 같은데, 전체 코드, 내가 표현 오류의 불법 시작을보고 있지 않다 .

http://www.java67.com/2016/08/how-to-fix-illegal-start-of-expression-error-in-java.html

+0

대단히 고마워요! 그게 효과가! 이제 나는 어떤 이유로 빈 출력을 얻고 있습니다. – BDL427

+0

main 메소드에서 응용 프로그램을 트리거하는 메소드를 호출했는지 확인하십시오 – rpfun12

관련 문제