소수 1째자리 = 1
힌트) 3.14 * 10 ==> (int) 31.4 ==> 31 % 10 ==> 1
package t0922;
import java.util.Scanner;
public class Test01 {
public static void main(String[] args) {
// TODO Auto-generated method stub
double a;
Scanner sc = new Scanner(System.in);
int i;
System.out.print("실수 입력:");
a = sc.nextDouble();
i = (int)(a*10);
System.out.printf("소수 첫째자리 =%d", i%10);
}
}
댓글 없음:
댓글 쓰기