import java.util.Arrays; public class Solution { public void div(String a, String b) { char[] chara = a.toCharArray(); char[] charb = b.toCharArray(); int[] numa = new int[a.length()]; int[] numb = new int[b.length()]; for (int i = 0; i < charb.length; i++) { numb[i] = charb[i]-'0'; // System.out.print(""+numb[i]); } System.out.println(""); for (int i = 0; i < chara.length; i++) { numa[i] = chara[i]-'0'; System.out.print(""+numa[i]); } System.out.println(""); int[] div = new int [1000]; int count = 0; while(compare(numa,numb)>0){ numa= div(numa,numb); addSelf(div,count); } StringBuffer sb = new StringBuffer(); sb.append(""+div+" "); for (int i = 0; i < numa.length; i++) { sb.append(""+numa[i]); } System.out.println(""+sb); } private void addSelf(int[] div, int count) { if (div[div.length-1]!=9) { div[div.length-1]++; }else{ int i = div.length-1; while (div[i]==9){ div[i] = 0; i--; } ; if (div[i]==0) { count++; }else{ div[i] ++; } } } private int[] div(int[] numa, int[] numb) { for (int i = 0; i < numb.length; i++) { int tmpa = numa[numa.length-i-1]; int tmpb = numb[numb.length-i-1]; int sub = tmpa-tmpb; int count = numa.length-1; if (sub>=0) { numa[numa.length-i-1] = sub; }else{ numa[numa.length-i-1] = sub+10; count =numa.length- i-1-1; while(numa[count]==0){ numa[count] =9; count--; } numa[count]--; if (numa[0]==0) { numa = Arrays.copyOfRange(numa,1, numa.length); } } } for (int i = 0; i < numa.length; i++) { // System.out.print(""+numa[i]); } //System.out.println(""); return numa; } int compare(int[] numa, int[] numb) { if (numa.length<numb.length) { return -1; }else if (numa.length>numb.length) { return 1; }else{ for (int i = 0; i < numb.length; i++) { if (numa[i]>numb[i]) { return 1; } if (numa[i]<numb[i]) { return -1; } } return 0; } } public static void main(String[] args) { Solution solution = new Solution(); String a = "1234578901234567890123456789"; String b = "1"; solution.div(a, b); } }