2017년 12월 5일 화요일

JAVA 실습) 직사각형의 너비와 높이를 입력받아 넓이와 둘레길이 계산

import java.util.Scanner;
public class Test01 {
 public static void main(String[] args) {
  Scanner sc = new Scanner(System.in);
  int w,h;
 
  System.out.print("가로, 세로 입력: ");
  w = sc.nextInt();
  h = sc.nextInt();
 
  System.out.printf("넓이 = %d\n둘레길이 = %d", w*h, (w+h)*2);
 }
}

import java.util.Scanner;
public class Test02 {
 public static void main(String[] args) {
  Scanner sc = new Scanner(System.in);
  int w,h;
 
  System.out.print("가로, 세로 입력: ");
  w = sc.nextInt();
  h = sc.nextInt();
 
  System.out.printf("넓이 = %d\n둘레길이 = %d", area(w,h), length(w,h));
 }
 static int area(int w, int h) {
  return w*h;
 }
 static int length(int w, int h) {
  return (w+h)*2;
 }
}


import java.util.Scanner;
class Rectangle {
 private int w, h;

 public int area() {
  return w*h;
 }
 public int length() {
  return (w+h)*2;
 }
 public void setW(int x) {
  w = x;
 }
 public void setH(int x) {
  h = x;
 }
 public String toString() {
  return "Rectangle[너비:" + w + " 높이:" + h + "]" ;
 }

}
public class Test03 {
 public static void main(String[] args) {
  Scanner sc = new Scanner(System.in);
  Rectangle MyRt = new Rectangle();
  System.out.print("가로, 세로 입력: ");
  MyRt.setW(sc.nextInt());
  MyRt.setH(sc.nextInt());
 
  System.out.printf("넓이 = %d\n둘레길이 = %d\n", MyRt.area(), MyRt.length());
  System.out.println(MyRt);
 }
}

댓글 없음:

댓글 쓰기

시스템 보안

1. 내컴퓨터는 해킹이 당한적 있는가? 있다. 2. 컴퓨터를 하게되면 해킹을 당한다. 무엇을 이용해 해킹을 하는가? 인터넷이 가장 보편적. 사회적인 공격(주변인이 사전정보를 가지고 해킹) 3. 대응을 어떻게 해야하나? 보안프로...