NAVER

질문
정수받고 입력 한정수를 분리하는프로그램

문제가 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%
닉네임zxcv****
작성일2013.07.08 조회수 548
질문자 채택
1번째 답변
전문인
채택답변수 2,616
달신
프로필 사진

자바스크립트 38위 분야에서 활동

본인 입력 포함 정보
프로필 더보기

 각 자리수별로 출력은 아래 소스를 이용하세요

 

 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));

 
 }

알아두세요!

위 답변은 답변작성자가 경험과 지식을 바탕으로 작성한 내용입니다. 포인트 선물할 때 참고해주세요.