对昨天语言进行巩固,做了两个题目
案例需求分析
1.首先接受从键盘输入的数字
2.分别求出用求除数和余数来求出各位数字
3.进行相加打印
案例代码
1.
package java1;
import java.util.Scanner;
public class name1 {
public static void main(String[] args) {
System.out.println("请输入三位数字");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a = n/100;
int b = n/10%10;
int c = n%10;
int sum = a+b+c;
System.out.println(sum);
}
}
2.
package java1;
import java.util.Scanner;
public class name {
public static void main(String[] args) {
System.out.println("请输入一个三位数字");
Scanner bill = new Scanner(System.in);
int n = bill.nextInt();
int a = n/100;
System.out.println(a);
int b = n/10%10;
System.out.println(b);
int c = n%10;
System.out.println(c);
}
}