java for문 10단위의 합

이미지
public class For_if { public static void main(String[] args) { // TODO Auto-generated method stub  youn1223@daum.net int sum; int i; System.out.println(); sum=0; for(i=1;i<=100;i++){ sum=sum+i; if(i%10==0){ System.out.println(1+"~" +i+" : "+sum); } } System.out.println(); sum=0; for(i=1;i<=100;i++){ sum=sum+i; if(i%10==0){ System.out.println(i-9+"~" +i+" : "+sum); sum=0; } } } }                                   결과                                   10단위의 합구하기

java array 성적입력받아 성적표 출력하기

이미지
import java.util.Scanner; public class Sungjuk { public static void  main(String[] args){ Scanner sc = new Scanner(System.in); System.out.print("이름 입력=>"); String name = sc.next();//문자열입력 System.out.print("HTML 점수=>"); double html=sc.nextDouble(); System.out.print("JSP 점수=>"); double jsp=sc.nextDouble(); System.out.print("JAVA 점수=>"); double java=sc.nextDouble(); double total=html+jsp+java; double avg=total/3.0; System.out.println(name+"학생의 점수"); System.out.println("HTML : "+html); System.out.println("JSP : "+jsp); System.out.println("JAVA : "+java); System.out.println("합계 : "+total); System.out.printf("평균 : %.2f\n" , avg); System.out.println("-------------------------------"); double[] arr = new double[3]; arr[0]=html; arr[1]=jsp; arr[2]=java; double max; double min;         int ...

java 로 Lotto 만들어 보기

이미지
import java.util.Scanner; public class Ex_04_25_Math_lotto_남동길 { public static void main(String[] args) { int[] lotto = new int[6]; // 1~45 중복 안되게 삽입      int[] my = new int[6]; // Scanner 입력      int count=0; // 맞은 갯수      Scanner sc = new Scanner(System.in);      int i,j;            for(i=0; i<lotto.length; i++){         lotto[i] = (int)((Math.random()*45)+1);         if(i>0){            for(j=0; j<i; j++){               while(lotto[i]==lotto[j]){                  lotto[i] = (int)((Math.random()*45)+1);               }            }         }      }          ...

java txt 파일 읽어서 추가로 쓰기 -> 성적처리

이미지
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; public class java_성적처리 { public static void main(String[] args) throws IOException { BufferedReader in = null; BufferedWriter out = null; in = new BufferedReader(new FileReader("sungjuk.txt")); out = new BufferedWriter(new FileWriter("sungjuk1.txt")); String line; while((line = in.readLine()) != null){ String[] tokens = line.split(" "); int sum = Integer.parseInt(tokens[1]) + Integer.parseInt(tokens[2]) + Integer.parseInt(tokens[3]); line = line + " " + sum; out.write(line); out.newLine(); //System.out.println(line); } in.close(); out.close(); } }                         결과                 ...

java ArrayList Book 객체 관리

이미지
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Scanner; class Book{ private String title; private String author; private int price; Book(){ } Book(String title,String author, int price){   this.title = title; this.author = author; this.price = price; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } public int getPrice() { return price; } public void setPrice(int price) { this.price = price; } @Override public String toString() { return title + ","+ author + ","+ price; } } public class Book_test { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader(System.in...

java ArrayList 로 객체관리 간단한 명함관리

이미지
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Scanner; class Card{ private String name; private String tel; public Card(String name, String tel){ this.name = name; this.tel = tel; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getTel() { return tel; } public void setTel(String tel) { this.tel = tel; } @Override public String toString() { return "Card [name=" + name + ", tel=" + tel + "]"; } } //1.명함추가2.삭제3.수정 4.보기 5.종료 :  public class Card_명함관리 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader(System.in)); // 빈공백도 읽은 enter 치기전까지 //System.out.print("입력하세요 : "); //System.out.println(str); Scanner sc = new Scanner(System.in); ArrayLi...

java HashMap 으로 간단한 단어검색

이미지
import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class HashMap_단어검색 { public static void main(String[] args) { Map<String, String> dic = new HashMap<String, String>(); dic.put("pencil", "연필"); dic.put("sky", "하늘"); dic.put("desk", "책상"); dic.put("face", "얼굴"); /* pencil - 연필 sky - 하늘 desk - 책살 face - 얼굴*/ Scanner sc = new Scanner(System.in); do{ System.out.println("찾는 단어는? "); String word = sc.next(); if(word.equals("q")){ break; } if(dic.get(word)==null){ System.out.println("잘못입력했습니다"); } else{ System.out.println("뜻 : "+dic.get(word)); } }while(true); System.out.println("프로그램을 종료합니다."); } }                        결과                        영어 키값을 입력하면 한글뜻을 찾는               ...