Experiment Source Code
This is a source code that does not use an array form
/*
2017/10/10 Wang Classroom Test 2
*/
Import Java.util.Scanner;
public class Number {
public static void Main (String args[]) {
Num n=new num ();
System.out.println ("Please enter an integer:");
Scanner input=new Scanner (system.in);
int Num=input.nextint ();
SYSTEM.OUT.PRINTLN ("digit" +n.numweishu (num));
}
}
Class num{
public int Numweishu (int a) {
int sum=0;
int num1;//to find the remainder 2
int num2;//Take integer
int Weishu;
num1=a%10; Take the last one.
NUM2=A/10; Take away all the last one
SUM=SUM+NUM1; Sum
Weishu=1; Statistics Number of digits
System.out.println (NUM1); Enter each bit
while (num2!=0)//Remove the last one without a number and then jump out of the loop
{
num1=num2%10;
NUM2=NUM2/10;
SUM=SUM+NUM1;
weishu=weishu+1;
System.out.println (NUM1);
}
System.out.println ("sum" +sum);
return Weishu;
}
}
Using the array source code
/*
2017/10/10 Wang Classroom Test 2
*/
Import Java.util.Scanner;
public class Number {
public static void Main (String args[]) {
Num n=new num ();
System.out.println ("Please enter an integer:");
Scanner input=new Scanner (system.in);
int Num=input.nextint ();
System.out.println ("\ n number of digits" +n.numweishu (num));
}
}
Class num{
public int num[];
public int Numweishu (int a) {
int num[]=new int[10];
int num1;//to find the remainder 2
int num2;//Take integer
int Weishu;
num1=a%10; Take the last one.
NUM2=A/10; Take away all the last one
NUM[0]=NUM1;
Weishu=1; Statistics Number of digits
while (num2!=0)//Remove the last one without a number and then jump out of the loop
{
num1=num2%10;
NUM2=NUM2/10;
NUM[WEISHU]=NUM1;
weishu=weishu+1;
}
int sum;
for (int i=weishu-1;i>=0;i--) {
Sum+=num[i];
System.out.print (num[i]+ "\ t");
}
System.out.print ("\ n sum result is" +sum);
return Weishu;
}
}
Java Classroom Test 2 (two ways)