자바 코드 작성중 질문입니다.

조회수 597회

안녕하세요

최근에 자바를 시작한 코딩 입문자입니다.

우선 상수를 입력한뒤

*와 +의 입력에 따라서

![이미지][1]

이렇게 혹은 이미지

이렇게 결과가 나오도록 만들려고 하였습니다.

그렇기 위해 코딩을 하였는데 계속 오류가 뜨고 완성이 안되고 있네요.

어느부분이 잘못됬고

어느부분을 어떻게

고쳐야 할지 알려주시면 감사하겠습니다.

private static Scanner console;
private static Scanner console2;

public static void main(String[] args) {
    console = new Scanner(System.in);
    console2 = new Scanner(System.in);
    System.out.print("Input the number: ");
    int n = console.nextInt();
     System.out.print("Input the operation:");
     int m = console2.nextInt();;

     if (m = '*') {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                System.out.printf("%3d ", i*j);
            }System.out.println();
        }

     }
      if(n='+')  
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                System.out.printf("%3d ", i+j);
            }System.out.println();
    }
}

}

  • (•́ ✖ •̀)
    알 수 없는 사용자

1 답변

  • 이렇게 해보세요.

    import java.util.Scanner;
    
    public class TestEverything {
        private static Scanner console;
        private static Scanner console2;
    
        public static void main(String[] args) {
            console = new Scanner(System.in);
            console2 = new Scanner(System.in);
            System.out.print("Input the number: ");
            int n = console.nextInt();
            System.out.print("Input the operation:");
            String m = console2.next();
    
            if ("*".equals(m)) {
                for (int i = 1; i <= n; i++) {
                    for (int j = 1; j <= n; j++) {
                        System.out.printf("%3d ", i * j);
                    }
                    System.out.println();
                }
    
            }
            if ("+".equals(m)) {
                for (int i = 1; i <= n; i++) {
                    for (int j = 1; j <= n; j++) {
                        System.out.printf("%3d ", i + j);
                    }
                    System.out.println();
                }
            }
        }
    }
    
    

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)