Deleting Duplicate Element Using HashSet

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import java.util.*;
 
public class Main {
 
    public static void main(String args[]){
 
    String[] fav = {"red","red","apple""apple""hallo"};
 
    Set<String> mySet  = new HashSet<String>();
    Collections.addAll(mySet,fav);
 
       System.out.println(mySet);
    }
}
cs

result / 결과

1
[red, apple, hallo]
cs

import java.util.Scanner;


public class Tax{

  public static void main(String[] args){

    int tax_commission = 1500;

    Scanner input = new Scanner(system.in);

    System.out.print("What do you do for your living? : ");

    String job = input.nextString();

    System.out.print("How much you get paid per month? : ");

    int salary = input.nextInt();

    

    System.out.println("Since your job is  " + job + " and get paid like " + salary +" this much, the tax you have pay for this year is : " + (commission + salary * 0.13) );

  }

}



[Java Programming] Java Method 자바 메소드 배우기


class Person{

String name;

String bloodType;


void speak(){

System.out.println("저의 이름은"+name+"이고 혈액형은"+bloodType+"입니다.");

}

}


class Cat{

String name;

}


public class Application{

public static void main(String[] args){

Person person1 = new Person();

person1.name = "Lin";

person1.bloodType = "A";

person1.speak();


Cat cat1 = new Cat();

cat1.name = "Kitty";

}

}


// 같은 package 안에 있으면 클래스 호출 가능.


[result]

저의 이름은 Lin이고 혈액형은 A입니다.

[Java Programming] 자바 2D Array 배우기


public class Array{

public static void main(String[] args){

int[][] numbers = {

{10, 30, 80},

{1, 3, 8}.

{100, 200, 300}

};

for (int x = 0 ; x < numbers.length ; x++){

for (int i = 0 ; i < numbers[x].length ; i ++){

System.out.print(numbers[x][i] + "\t");

}

System.out.println();

}

}

}


[result]

10    30    80

1    3    8    

100    200    300


[Java Programming] 배열 배우기 _ 2, Array_2


public class Application{

public static void main(String[] args){

String[] fruits = {'Apple', 'orange', 'banana'};

System.out.println(fruits[0]);


for(String text : fruits){

    System.out.println(text);

}

}

}


[result]

Apple

Apple

orange

banana

+ Recent posts