import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
public class Main {
public static void main(String[] args) throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
StringBuffer sb = new StringBuffer("");
String m = "";
while(true) {
m=br.readLine();
if("0".equals(m))
break;
BigInteger x=new BigInteger(m);
if(x.remainder(BigInteger.valueOf(9)).compareTo(BigInteger.ZERO)==0){
sb.append(m).append(" is a multiple of 9 and has 9-degree ").append(sum(m,true)).append(".\n");
}else{
sb.append(m).append(" is not a multiple of 9.\n");
}
}
System.out.print(sb);
}
static int sum (String x,boolean flag){
if("9".equals(x)&&flag)
return 1;
if("9".equals(x)&&!flag)
return 0;
int count=0;
for(int i=0;i<x.length();i++){
count+=x.charAt(i)-'0';
}
return 1+sum(count+"",false);
}
}
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
public class Main {
public static void main(String[] args) throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
StringBuffer sb = new StringBuffer("");
String m = "";
while(true) {
m=br.readLine();
if("0".equals(m))
break;
BigInteger x=new BigInteger(m);
if(x.remainder(BigInteger.valueOf(9)).compareTo(BigInteger.ZERO)==0){
sb.append(m).append(" is a multiple of 9 and has 9-degree ").append(sum(m,true)).append(".\n");
}else{
sb.append(m).append(" is not a multiple of 9.\n");
}
}
System.out.print(sb);
}
static int sum (String x,boolean flag){
if("9".equals(x)&&flag)
return 1;
if("9".equals(x)&&!flag)
return 0;
int count=0;
for(int i=0;i<x.length();i++){
count+=x.charAt(i)-'0';
}
return 1+sum(count+"",false);
}
}
No comments:
Post a Comment