238 - 数字统计
Description
输入一个长整型的数,统计其中0、1、2、3、4、5、6、7、8、9各个数字的个数,并将结果合成一个整数。(前面的0不输出)
Input
长整型数
Output
合成后的整数
Sample Input
234353632
Sample Output
24111000
MyAnswer
import java.util.*;
//H7EaGRl7
public class Main {
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
long num = scan.nextLong();
System.out.println(num);
int a[] = {0,0,0,0,0,0,0,0,0,0};
String s = String.valueOf(num);
System.out.println(s.charAt(0));
for(int i=0; i<10; i++)
if (s.charAt(i) == '0') {
a[0]++;
} else if (s.charAt(i) == '1') {
a[1]++;
} else if (s.charAt(i) == '2') {
a[2]++;
} else if (s.charAt(i) == '3') {
a[3]++;
} else if (s.charAt(i) == '4') {
a[4]++;
} else if (s.charAt(i) == '5') {
a[5]++;
} else if (s.charAt(i) == '6') {
a[6]++;
} else if (s.charAt(i) == '7') {
a[7]++;
} else if (s.charAt(i) == '8') {
a[8]++;
} else if (s.charAt(i) == '9') {
a[9]++;
}
long res=0;
for(int i=0; i<10; i++){
res = res*10 + i;
}
System.out.println(res);
}
}
239 - 家具类
Description
构建家具类Furniture,包括长、宽、高,均为整数(cm)。提供相应的构造函数和get、set函数。
Main函数里构造家具对象,并调用相应的函数。
Input
家具对象的长宽高
Output
家具对象的相关属性
Sample Input
50 60 100
Sample Output
100
50
60
Pre Append Code
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Furniture f = new Furniture(sc.nextInt(),sc.nextInt(),sc.nextInt());
System.out.println(f.getHeight());
System.out.println(f.getLength());
System.out.println(f.getWidth()