package struct;


import java.util.Scanner;


import struct.Record;


public class Program3

{

//**********************메인함수**********************

public static void main(String[] args) 

{

Scanner scan = new Scanner(System.in);

int num;

System.out.print("몇명의 성적을 관리 하겠습니까?");

num = scan.nextInt();

Record[] records = new Record[num];

int size=0;

int menu;

exit:while(true)

{

switch(menu = inputMenu())

{

case 1:

size = inputRecord(records, size, num);

break;


case 2:

printRecord(records, size);

if(size == num) //성적관리숫자 만족시킬경우 프로그램종료

break exit;

break;

case 3:

System.out.println("프로그램이 종료됩니다.");

break exit;

default:

System.out.println("입력 오류");

}

}

}

//**********************메뉴출력함수**********************

static int inputMenu() 

{

Scanner scan= new Scanner(System.in);

int menu;

System.out.println("┌─────────────────┐");

System.out.println("│                   메인  메뉴                  │");

System.out.println("└─────────────────┘");

System.out.print("\t\t1.성적 입력\n");

System.out.print("\t\t2.성적 출력\n");

System.out.print("\t\t3.종료\n");

menu = scan.nextInt();

return menu;

}

//**********************성적입력함수**********************

static int inputRecord(Record[] record, int size, int num) 

{

Scanner scan= new Scanner(System.in);

int kor, eng, math; //임시변수선언

int current=size;

System.out.println("┌─────────────────┐");

System.out.println("│                   성적  입력                  │");

System.out.println("└─────────────────┘");

while(true)

{

do{

System.out.print("\t\t국어 :");

kor = scan.nextInt();

if(kor<0 || kor>100)

System.out.println("범위벗어남");

}

while(kor<0 || kor>100);

do{

System.out.print("\t\t영어 :");

eng = scan.nextInt();

if(eng<0 || eng>100)

System.out.println("범위벗어남");

}

while(eng<0 || eng>100);

do{

System.out.print("\t\t수학 :");

math = scan.nextInt();

if(math<0 || math>100)

System.out.println("범위벗어남");

}

while(math<0 || math>100);

record[current] = new Record();

record[current].kor=kor;

record[current].eng=eng;

record[current].math=math;

current++;

System.out.print("끝내시겠습니까? 1=계속,2=끝");

int isContinue = scan.nextInt();

if(isContinue == 1)

{

if(num==current)

return current;

else

continue;

}

else

return current;

}

}

//**********************성적출력함수**********************

static void printRecord(Record[] records, int size)

{

System.out.printf("┌─────────────────┐\n");

System.out.printf("│           @본인 이름 성적표@           │\n");

System.out.printf("├──┬──┬──┬──┬──┬──┤\n");

System.out.printf("│번호│국어│영어│수학│총점│평균│\n");

for(int i=0 ; i<size ; i++)

{

Record record = records[i];

int total = record.kor + record.eng + record.math;

float avg = total / 3.0f;

System.out.printf("├──┼──┼──┼──┼──┼──┤\n");

System.out.printf("│%-5d│%-5d│%-5d│%-5d│%-5d│%4.2f│

\n",i+1,record.kor,record.eng,record.math,total,avg);

}

System.out.printf("└──┴──┴──┴──┴──┴──┘\n");

}

}




package struct;



import java.util.Scanner;



public class Program2

{

	

	static int inputMenu() //메뉴출력함수

	{

		Scanner scan= new Scanner(System.in);

		int menu;

		

		System.out.println("┌─────────────────┐");

		System.out.println("│                   메인  메뉴                  │");

		System.out.println("└─────────────────┘");

		System.out.print("\t\t1.성적 입력\n");

		System.out.print("\t\t2.성적 출력\n");

		System.out.print("\t\t3.종료\n");

		menu = scan.nextInt();

		

		return menu;

		

		

	}

	

	

	static void inputRecord(Record record) //성적입력함수

	{

		Scanner scan= new Scanner(System.in);

		int kor, eng, math; //임시변수선언

		

						System.out.println("┌─────────────────┐");

						System.out.println("│                   성적  입력                  │");

						System.out.println("└─────────────────┘");



						

					do{

							System.out.println("\t\t국어 :");

							kor = scan.nextInt();

							if(kor<0 || kor>100)

								System.out.println("범위벗어남");

						}

						while(kor<0 || kor>100);

						

					

					do{

							System.out.print("\t\t영어 :");

							eng = scan.nextInt();

							if(eng<0 || eng>100)

								System.out.println("범위벗어남");

						}

					while(eng<0 || eng>100);



					

					do{

							System.out.print("\t\t수학 :");

							math = scan.nextInt();

							if(math<0 || math>100)

								System.out.println("범위벗어남");

						}

					while(math<0 || math>100);

					

					record.kor=kor;

					record.eng=eng;

					record.math=math;

					

					

					

	}

	

	static void printRecord(Record record)//성적출력함수

	{

					

						int total = record.kor + record.eng + record.math;

						float avg = total / 3.0f;	

									

						System.out.printf("┌─────────────────┐\n");

						System.out.printf("│           @본인 이름 성적표@           │\n");

						System.out.printf("├──┬──┬──┬──┬──┬──┤\n");

						System.out.printf("│번호│국어│영어│수학│총점│평균│\n");

					for(int i=0 ; i<3 ; i++)

						{

							System.out.printf("├──┼──┼──┼──┼──┼──┤\n");

							System.out.printf("│%-5d│%-5d│%-5d│%-5d│%-5d│%4.2f│\n",i+1,record.kor,record.eng,record.math,total,avg);

						}

						System.out.printf("└──┴──┴──┴──┴──┴──┘\n");

	}

	

	public static void main(String[] args) 

	{

		Record record = new Record();

		

		

/*		int kor=0;

		int eng=0;

		int math=0;*/

		int menu;

		int i;

		

		Scanner scan = new Scanner(System.in);

		

		exit:while(true)

		{

			/*menu = inputMenu();*/

			

/*			System.out.println("┌─────────────────┐");

			System.out.println("│                   메인  메뉴                  │");

			System.out.println("└─────────────────┘");

			System.out.print("\t\t1.성적 입력\n");

			System.out.print("\t\t2.성적 출력\n");

			System.out.print("\t\t3.종료\n");

			menu = scan.nextInt();*/

		

			switch(menu = inputMenu())

			{

			

			case 1:

				

			inputRecord(record);

			

	

					//inputRecord(kor,eng,math);

/*					System.out.println("┌─────────────────┐");

					System.out.println("│                   성적  입력                  │");

					System.out.println("└─────────────────┘");



					

				do{

						System.out.println("\t\t국어 :");

						kor = scan.nextInt();

						if(kor<0 || kor>100)

							System.out.println("범위벗어남");

					}

					while(kor<0 || kor>100);

					

				

				do{

						System.out.print("\t\t영어 :");

						eng = scan.nextInt();

						if(eng<0 || eng>100)

							System.out.println("범위벗어남");

					}

				while(eng<0 || eng>100);



				

				do{

						System.out.print("\t\t수학 :");

						math = scan.nextInt();

						if(math<0 || math>100)

							System.out.println("범위벗어남");

					}

				while(math<0 || math>100);

				*/

				break;



				

			case 2:

				

			printRecord(record);

				

					/*total = kor + eng + math;

					avg = total / 3.0f;	

								

					System.out.printf("┌─────────────────┐\n");

					System.out.printf("│           @본인 이름 성적표@           │\n");

					System.out.printf("├──┬──┬──┬──┬──┬──┤\n");

					System.out.printf("│번호│국어│영어│수학│총점│평균│\n");

				for(i=0 ; i<3 ; i++)

					{

						System.out.printf("├──┼──┼──┼──┼──┼──┤\n");

						System.out.printf("│%-5d│%-5d│%-5d│%-5d│%-5d│%4.2f│\n",i+1,kor,eng,math,total,avg);

					}

					System.out.printf("└──┴──┴──┴──┴──┴──┘\n");*/

				

					break;

					

			case 3:

				

					System.out.println("프로그램이 종료됩니다.");	

					break exit;

					

			default:

					System.out.println("입력 오류");

			}

		}

	}

}


package function;



import java.util.Random;



public class Program 

{

	

	static void genLotto(int[] lotto)//로또 번호 생성 함수

	{

		Random rand = new Random();

		

		for(int i=0; i<6; i++)

		lotto[i]=rand.nextInt(45)+1;

	}

	

	

	static void printLotto(int[] lotto)//로또 번호 출력 함수

	{

		for(int i=0; i<6; i++)

			System.out.printf("%d ", lotto[i]);

	}

	

	static void sortLotto(int[] lotto)//로또 번호 비교 정렬

	{

		int t;

		

		for(int k=0; k<5; k++)

			for(int i=0; i<5; i++)

			if(lotto[i]>lotto[i+1])

			{

				t=lotto[i];

				lotto[i]=lotto[i+1];

				lotto[i+1]=t;

				printLotto(lotto);

				System.out.println();

			}

		

	}

	

	public static void main(String[] args)

	{

		

		int[] lotto = new int[6];



		genLotto(lotto);



		sortLotto(lotto);



	}

		

}


package calendar;



import java.util.Random;



public class my

{

	public static void main(String[] args)

	{

		int i,j,t;

		

		Random rand = new Random();

		int[] lotto = new int[6];

		

				

		//난수 발생 후 중복검사

		for(i=0 ; i<6 ; i++)

			{

				lotto[i] = rand.nextInt(45)+1;

				for(j=i-1; j>=0; j--)

					if(lotto[i]==lotto[j])

						i--;

					

				}

					

			

		

		System.out.println();



		// 크기비교후 정렬

		for(j=0; j<5; j++)

			for(i=0; i<5; i++)

			if(lotto[i]>lotto[i+1])

			{

				t=lotto[i];

				lotto[i]=lotto[i+1];

				lotto[i+1]=t;

			}

				for(j=0; j<6; j++)

					System.out.printf("%d\t", lotto[j]);

				System.out.println();

			}

	}

+ Recent posts