2013-10-21 1 views
-4

공공 정적 공백 라인에 오류가 계속 발생하고 system.out에 연간 매출액이 입력됩니다. 내가 뭘하려고 고정 급여와 수수료를 감안하여 연간 매출을 얻을 후 입력 연간 매출에 사용자를 얻을 수 있습니다 :자바 파일 작성

import java.util.Scanner; 
import java.io.BufferedReader; 

public class commission { 

    public static void main(String[] args) 

      Scanner input = new Scanner(System.in; 
      BufferReader br = new BufferReader(instream); 

      System.out.println("Enter your annual sales"); 
      String annual = br.readLine(); 

      int salary = 75_502_81; 
      int com = 38_28; 
      int compensation = annual * com + salary; 

} 
+2

오른쪽 괄호가 누락되었습니다. 그리고 왼쪽 버팀대. – Makoto

+0

이것도 마찬가지입니다. 파일에 쓰는 것과 아무런 관련이 없습니다. – MadProgrammer

+0

int에는 _과 같은 특수 문자가 있어서는 안됩니다. 제거하십시오. – Hariharan

답변

0

즉각적인 문제가 누락 열린 중괄호 ({가)이며 폐쇄 괄호 ())

BufferReader으로 그러한 클래스가 없습니다
public static void main(String[] args) { 
             ^--- This is important... 
    Scanner input = new Scanner(System.in); 
              ^--- Also important :P 
    BufferReader br = new BufferReader(instream); 

    System.out.println("Enter your annual sales"); 
    String annual = br.readLine(); 

    int salary = 75_502_81; 
    int com = 38_28; 
    int compensation = annual * com + salary; 
} 

, 난 당신이 그런 변수 instream 요에 선언되지 있습니다 BufferedReader

의미 생각 u 코드, 나는 당신이 input을 의미 할 수도 있다고 생각하지만, BufferedReader은 유효한 입력 유형으로 input을 취하지 않으므로 여기에 의도가 무엇인지 확실하지 않습니다.

캐치되지 않는 IOException

당신은 내가 또한 75_502_8138_28이 의미하는 가정하는 것에 대해 궁금 try-catch

의 사용을 통해이를 해결할 수 있습니까? int 값은 숫자 이외의 값을 포함 할 수 없습니다 ...

annual 또한입니다. 즉, 어떤 수학 연산도 수행 할 수 없음을 의미합니다.

당신은 먼저 int에 값을 변환해야합니다 ...

public static void main(String[] args) { 

    Scanner input = new Scanner(System.in); 
    BufferedReader br = null; 

    try { 
     br = new BufferedReader(instream); 
     System.out.println("Enter your annual sales"); 
     String annual = br.readLine(); 

     int salary = 7550281; 
     int com = 3828; 
     int compensation = Integer.parseInt(annual) * com + salary; 

    } catch (IOException exp) { 
     exp.printStackTrace(); 
    } finally { 
     try { 
      br.close(); 
     } catch (Exception exp) { 
     } 
    } 
} 

하지만

public static void main(String[] args) { 

    Scanner input = new Scanner(System.in); 
    System.out.println("Enter your annual sales"); 
    String annual = input.nextLine(); 

    int salary = 7550281; 
    int com = 3828; 
    int compensation = Integer.parseInt(annual) * com + salary; 

} 

이 같은 일을 할 때 왜에 나의 머리를 긁적 왼쪽 해요 ...

+0

닫기. 그러나 그게 전부가 아닙니다. – Makoto

+0

나는 "즉각적인" – MadProgrammer

+0

* Touche *라고 했어. 그러나 그렇다고해도 ... – Makoto

0

int compensation = annual * com + salary; 
할 수 없습니다3210

연간 당신은 어쩌면이

Integer.parseInt(annual); 

같은 문자열을 정수로 구문 분석 할 필요가 : 문자열이기 때문에이 도움이 :) 희망

+0

니스 픽업 ...! – MadProgrammer

+0

감사합니다. 나는 모든 사람들의 의견을 사용했다. 실종 된 것을 추가했습니다. 완충 장치를 꺼내었고 parseint를 추가했습니다. –

0

코드에서 몇 가지 문제가 있습니다

은 현재 오류의 이유는 @Makoto가 언급 한대로 right paren. And a left brace이 누락되었습니다.

이 시도 : 또한 누락 된 닫는 중괄호

Scanner input = new Scanner(System.in);<----- 

public static void main(String[] args) { 
    Scanner input = new Scanner(System.in); 
    System.out.println("Enter your annual sales"); 

    int annual = Integer.parseInt(input.nextLine()); 
    int salary = 75_502_81; 
    int com = 38_28; 
    int compensation = annual * com + salary; 
    System.out.println(compensation); 
} 
+0

덕분에이 일을 도와주세요. –

+0

@ 모 마크 여러분 안녕하세요. – Bhushan

0

을 내가 스캐너 객체의 BufferedReader로가는 경우없는 확신, 그것은

0

이 있습니다 독자 개체가 필요합니다 구문 오류가 거의 없습니다. 아래 코드를 시도하여 문제를 해결해야합니다.

public class Commission { 

    public static void main(String[] args) { 
      Scanner input = new Scanner(System.in); 
      System.out.println("Enter your annual sales"); 
      String annual = input.nextLine(); 

      int salary = 75_502_81; 
      int com = 38_28; 
      int compensation = Integer.parseInt(annual) * com + salary; 
      System.out.println("compensation is: "+compensation); 
    } 
}