Skip to main content

Posts

Showing posts with the label 자바

자바 whlie 문 - 통과/낙제 학생들의 수 계산방법

# # package pro_04_08;   import java.util.Scanner;   public class PassFail {   public static void main(String[] args ) { // TODO Auto-generated method stub int grade ; int numStudents = 0; int numPass = 0; int numFail = 0; Scanner scan = new Scanner(System. in ); System. out .println( " 첫 번째 점수 ( 종료하려면 음수 ) 를 입력하세요 : " ); grade = scan .nextInt(); while ( grade >=0) { numStudents ++; if ( grade > 60) numPass ++; else numFail ++; System. out .println( " 다음 점수 ( 종료하려면 음수 ) 를 입력하세요 : " ); grade = scan .nextInt(); }   System. out .println( " 학생들의 수 : " + numStudents ); System. out .println( " 통과한 학생수 " + numPass ); System. out .println( " 실패한 학생수 " + numFail );   } } #

문자열 역순으로 출력

# # package pro_04_08;   import java.util.Scanner;   public class ReverseString {   public static void main(String[] args ) { // TODO Auto-generated method stub String str ; int length ; int index ; char ch ; String rest ; String outputStr = "" ; Scanner scan = new Scanner(System. in ); System. out .println( " 길이가 3 인 문자열을 입력하세요 : " ); str = scan .next(); System. out .println( " 입력 문자열 : " + str ); length = str .length(); index = str .indexOf( " 궁 " ); ch = str .charAt( length -1); rest = str .substring(1, length -1); outputStr = str .substring(0, length -2); //System.out.println("length : " + length); //System.out.println("rest : " + rest); //System.out.println(" ch : " + ch ); //System.out.println("index : " + index); //System.out.println(" outputstr : " + outputStr);   System. out .p

원기둥 부피와 표면적 계산

# # package pro_04_08;   import java.util.Random;   public class CalculateVolume {   public static void main(String[] args ) { // TODO Auto-generated method stub final double PI = 3.14159; int radius ; double volume , height , area ; Random generator = new Random(); radius = generator .nextInt(10)+1; height = generator .nextInt(10)+1; volume = PI * radius * radius * height ; area = 2 * PI * radius * height ; System. out .println( " 반지름 = " + radius ); System. out .println( " 원기둥 = " + height ); System. out .println( " 부피 = " + volume ); System. out .println( " 표면적 = " + area ) #

전화번호 생성기

# # package pro_04_08;   import java.util.Random;   public class PhoneNumbers {   public static void main(String[] args ) { // TODO Auto-generated method stub Random rand = new Random(); String PhoneNumber = "0" ; PhoneNumber += rand .nextInt(5)+2; PhoneNumber += rand .nextInt(5)+1; PhoneNumber += "-" ; PhoneNumber += rand .nextInt(10); PhoneNumber += rand .nextInt(10); PhoneNumber += rand .nextInt(10); PhoneNumber += "-" ; PhoneNumber += rand .nextInt(10); PhoneNumber += rand .nextInt(10); PhoneNumber += rand .nextInt(10); PhoneNumber += rand .nextInt(10); System. out .println( " 생성된 전호번호 : " + PhoneNumber ); #

삼각형 빗변구하기double _Math.sqart

# # import java.util.Scanner;   public class Calhypotenuse {   public static void main(String[] args ) { // TODO Auto-generated method stub double a , b , c ; Scanner scan = new Scanner(System. in ); System. out .println( " 밑변을 입력하세요 : " ); a = scan .nextDouble(); System. out .println( " 높이를 입력하세요 : " ); b = scan .nextDouble(); c = Math. sqrt ( a * a + b * b ); System. out .println( " 빗변의 길이는 : " + c + " 이다 ." ); #

문자열 결합_String indexof

# # import java.util.Scanner;   public class ChangeString {   public static void main(String[] args ) { // TODO Auto-generated method stub String name = "i love u" ; int change = name .indexOf( "love" ); String name1 = "u" ; Scanner scan = new Scanner(System. in ); System. out .println( name + " 입력하세요 : " ); scan .nextLine(); name = name .substring(0, change ) + "hate" ; System. out .println( name + " " + name1 );   }   } #