HR자바 Java Static Initializer Block

개요[ | ]

HR자바 Java Static Initializer Block
해커랭크 Java
# 문제 비고
HR자바 Introduction e
1 HR자바 Welcome to Java!
2 HR자바 Java Stdin and Stdout I
3 HR자바 Java If-Else
4 HR자바 Java Stdin and Stdout II
5 HR자바 Java Output Formatting
6 HR자바 Java Loops I
7 HR자바 Java Loops II
8 HR자바 Java Datatypes
9 HR자바 Java End-of-file
10 HR자바 Java Static Initializer Block
11 HR자바 Java Int to String
12 HR자바 Java Date and Time
13 HR자바 Java Currency Formatter

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {
    static int B;
    static int H;
    static boolean flag = true;
    static {
        Scanner sc = new Scanner(System.in);
        B = sc.nextInt();
        H = sc.nextInt();
        if( B<=0 || H<=0 ) {
            flag = false;
            System.out.println("java.lang.Exception: Breadth and height must be positive");
        }
    }
    public static void main(String[] args){
        if(flag){
            int area=B*H;
            System.out.print(area);
        }
    }//end of main
}//end of class
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}