자바 프로그래밍/코드
사용자가 원하는 랜덤범위의 값 추출 / 주사위 굴리기, 합계 구하기
구리Guri
2020. 2. 11. 00:36
import java.util.Scanner;
//사용자가 원하는 랜덤범위의 값 추출
public class Quiz_03 {
public static void main(String[] args) {
/*
System.out.println("0~9까지의 랜덤수 : " + (int)(Math.random()*(9-0+1)+0));
System.out.println("1~10까지의 랜덤수 : " + (int)(Math.random()*(10-1+1)+1));
System.out.println("20~35까지의 랜덤수 : " + (int)(Math.random()*(35-20+1)+20));
System.out.println("0 또는 1 : " + (int)(Math.random()*(1-0+1)+0));
*/
/*
Scanner sc = new Scanner(System.in);
int start=0;
int end=0;
double random;
System.out.print("시작하는 수 : ");
start=Integer.parseInt(sc.nextLine());
System.out.print("끝나는 수 : ");
end =Integer.parseInt(sc.nextLine());
random = Math.random()*(end-start+1)+start;
System.out.println(start+"~"+end+"까지의 랜덤수 : " + (int)random);
*/
//주사위 굴리기, 합계 구하기
int dice1=0;
int dice2=0;
int sum=0;
System.out.println("주사위 굴리기!!!!");
dice1=(int)(Math.random()*(6-1+1)+1);
dice2=(int)(Math.random()*(6-1+1)+1);
sum=dice1+dice2;
System.out.println("첫번째 주사위 : " +dice1);
System.out.println("두번째 주사위 : " +dice2);
System.out.println("두 주사위의 합 : " + sum);
}
}