码迷,mamicode.com
首页 > 其他好文 > 详细

hw 校招机试

时间:2016-08-22 12:32:43      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

 1 package test;
 2 
 3 import java.util.Scanner;
 4 
 5 public class Main {
 6 
 7     public static void main(String[] args) {
 8         // TODO Auto-generated method stub
 9         Scanner in = new Scanner(System.in);
10         int a = 0, n = 0;
11         int ans = 0;
12         while(in.hasNext()){
13             a = in.nextInt();
14             n = in.nextInt();
15             ans = countsum(a,n);
16             System.out.println(ans);
17         }
18     }
19     
20     public static int countsum(int a,int n){
21         int sum = 0,tmp = a;
22         for(int i = 0; i < n; i++){
23             sum += tmp;
24             tmp = tmp*10 + a;
25         }
26         return sum;
27     }
28 
29 }
30 
31 
32 package test;
33 
34 import java.util.Scanner;
35 
36 public class Main {
37 
38     public static void main(String[] args) {
39         // TODO Auto-generated method stub
40         Scanner in = new Scanner(System.in);
41         int max = 0, min = 0;
42         int cnt = 0;
43         String[] numstr;
44         if(in.hasNext()){
45             String str = in.nextLine();
46             numstr = str.split(",");
47             int[] num = new int[numstr.length];
48             for(int i = 0; i < numstr.length; i++){
49                 num[i] = Integer.parseInt(numstr[i]);
50             }
51             max = num[0];min = num[0];
52             for(int i = 0; i < num.length; i++){
53                 if(num[i] > max) {
54                     min = max;
55                     max = num[i];
56                 }
57                 else if(num[i] > min) {
58                     min = num[i];
59                 } 
60             }
61                 
62         }
63         System.out.println(max + "," + min);
64     }
65 }

 

hw 校招机试

标签:

原文地址:http://www.cnblogs.com/guoguolan/p/5794879.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!