과제

자바, 리눅스 과제 6주차

e리터 2021. 4. 15. 21:37

18p

public class circle{
	int radius;
    String name;
    
    public circle(){
    	radius=1;name="";
       }
    public circle(int r, String n){
    	radius = r; 
        name=n;
    }
    public double getAr(){
    	return 3.14*radius*radius;
    }
    public static void main(String[] args){
    	circle pizz = new circle(10, "자바피자");
        double ar=pizza.getAr();
        System.out.println(pizz.name+"의 면적은"+ar);
        circle donut = new circle();
        donut.name="도넛피자";
        ar=donut.getAr();
        System.out.println(donut.name+"의 면적은"+ar);
    }
}

20p

public class book{
	String title;
    String author;
    public book(String t){
    	title=t;author="작자미상";
    }
    public book(String t, String a){
    	title=t;
        author=a;
    }
    public static void main(String[] args){
    	book littlePrince = new book("어린왕자", "생택쥐페리");
        book loveStory = new book("춘향전");
        System.out.println(littlePrince.title+""+littlePrince.author);
        System.out.println(loveStory.tile+""+loveStory.author);
    }
}

28p

public class book1{
	String title;
    String author;
    vold show(){
    	System.out.println(title+" "+author);
    }
    public book1(){
    	this("","");
        System.out.println("생성자 호출된");
    }
    public book1(String title){
    	this(title,"전자마상");
    }
    public book1(String title, String author){
    	this.title=title;
        this.author=author;
    }
    public static void main(String[] args){
    	book1 littlePrince=new book1("어린왕자", "생력쥐페리");
        book1 loveStory=new book1("춘향전");
        book1 emtybook=new book1();
        loveStory.show();
    }
}

구구단

public class multiplication_table{
	public static void main(String[] args){
    	int i,j;
        for(i=1;i<=9;i++){
        	for(j=2;j<=9;j++){
            	System.out.print(i+"*"+j+"="+(i*j));
            }
            System.out.println();
        }
   	}
}

copy.c

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
main(int argc, char *argv[])
{ 
   int fd1, fd2, n;
   char buf[BUFSIZ];
   if (argc != 3) { 
      fprintf(stderr,"사용법: %s file1 file2 \n",        
               argv[0]); 
      exit(1); 
   }
   if ((fd1 = open(argv[1], O_RDONLY)) ==    -1) {
      perror(argv[1]);
      exit(2); 
   }
   if ((fd2 =open(argv[2], O_WRONLY |
      O_CREAT|O_TRUNC 0644)) == -1) {
      perror(argv[2]);
      exit(3); 
   }

   while ((n = read(fd1, buf, BUFSIZ)) > 0) 
      write(fd2, buf, n);   // 읽은 내용을 쓴다.
   exit(0); 
}