문제가 10000보다 작은 정수를입력 받아서 천의자리 백자리 십자리 일의자리로 분리하는프로그램을 만드는
겁니다 그런데 이것을 나눗셈과 나머지연산을 사용하라네요
package helllo;
import java.util.Scanner;
public class TeatTest {
public static void main(String[] args) {
int i ;
int z ;
int x ;
int v ;
int c ;
Scanner scan = new Scanner (System.in);
System.out.print("정수를 입력하시오:");
i= scan.nextInt();
System.out.printf("천의 자리:");
z = scan.nextInt();
System.out.printf("백의 자리:");
x = scan.nextInt();
System.out.printf("십의 자리:");
v = scan.nextInt();
System.out.printf("일의 자리:");
c = scan.nextInt();
이렇게 짜는거맞나요
소스좀 더추가해서 짜주세요 !!!
- 질문수79
- 채택률91.1%
- 마감률97.8%
각 자리수별로 출력은 아래 소스를 이용하세요
public static void main(String[] args) throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
System.out.print("정수를 입력하시오:");
String str = br.readLine();
System.out.println("천의 자리:" + str.substring(0,1));
System.out.println("백의 자리:"+str.substring(1,2));
System.out.println("십의 자리:"+str.substring(2,3));
System.out.println("일의 자리:"+str.substring(3,4));
}
위 답변은 답변작성자가 경험과 지식을 바탕으로 작성한 내용입니다. 포인트 선물할 때 참고해주세요.
2013.07.08.