Java机考

2019-03-27  本文已影响0人  robtomb_
System.out.println(String.format("%.2f",24.449));
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;
public class Test{
    
    public static long getsum(String str){
        long sum = 0l;
        for(int  i = 0 ; i < str.length() ; i++){
            int x = Integer.parseInt(str.charAt(i)+"");
            if( x % 2 == 0)
                sum += x;
        }
        return sum;
    }
    
    public static int getdiv(int n,int b){
        int count = 0; 
        for(int i = 1 ; i <= n ; i++){
            if( i % b == 0){
                count++;
            }
        }
        return count;
    }
    
    public static int step(int s){
        if( s == 0)
            return 0;
        if( s == 1 )
            return 1;
        if( s == 2 )
            return 2;
        return step(s-1) + step(s - 2);
    }
    
    public static boolean primenum(int num){
        if( num <= 3 )
            return num >1;
        for( int i = 2; i < num ; i ++){
            if( num % i == 0)
                return false;
        }
        return true;
    }
    
    public static void leapyear(){
        for(int i = 1990 ; i <= 2010 ; i++){
            if( (i % 4 == 0 && i % 100 != 0 ) || (i % 400 == 0))
                System.out.println(i);
        }
    }
    
    public static String otherstr(String str){
        String newstr = "";
        
        for(int i = 0 ; i < str.length() ; i++){
            char ch = str.charAt(i);
            if( ch >= 'a' && ch <= 'z' )
                ch = (char)( 'z' - ch + 'a');
            if( ch >= 'A' && ch <= 'Z' )
                ch = (char)('Z' - ch + 'A');
            newstr += ch;
        }
        return newstr;
    }
    
    public static int jiecheng(int num){
        if( num == 1)
            return 1;
        return jiecheng(num - 1) * num;
    }
    
    public static int[] getswitch(int [] arr){
        int maxi = 0;
        int mini = 0;
        for(int i = 0 ; i < arr.length ; i++){
            if(arr[maxi] < arr[i])
                maxi = i;
            if(arr[mini] > arr[i])
                mini = i;
        }
        int temp = arr[arr.length - 1];
        arr[arr.length - 1] = arr[maxi];
        arr[maxi] = temp;
        
        temp = arr[0];
        arr[0] = arr[mini];
        arr[mini] = temp;
        
        return arr;
    }
    
    public static int eatpeach(int days){
        int sum = 1;
        for( int i = days; i > 1 ; i--){
            sum = (sum + 1) * 2;
        }
        return sum;
    }
    
    public static String replaceAB(String stra,String strb){
        String str = "";
        for( int i = 0 ; i < stra.length() ; i++){
            String s = stra.charAt(i) + "";
            if( (!str.contains(s)) && (!strb.contains(s)) ){
                str += s;
            }
        }
        return str;
    }
    
    public static String kaisacode(String str){
        String newstr = "";
        for(int i = 0 ; i < str.length() ; i++){
            char ch = str.charAt(i);
            if( ch >= 'a' && ch <= 'z' )
                ch = (char) ((ch - 'a' + 5) % 26 + 'a' );
            if( ch >= 'A' && ch <= 'Z' )
                ch = (char) ( (ch - 'A' + 5 ) % 26 + 'A');
            newstr +=  ch;
        }
        return newstr;
    }
    
    public static String nopeate(String str){
        String newstr = "";
        for(int i = 0 ; i < str.length() ; i++){
            for(int j = i ; j < str.length() ; j++){
                
            }
            
        }
        return newstr;
    }
    
    public static int miaoshu(String str){
        String [] strarr = str.split(":");
        int h = Integer.parseInt(strarr[0]);
        int m = Integer.parseInt(strarr[1]);
        int s = Integer.parseInt(strarr[2]);
        return h * 60 * 60 + m * 60 + s;
    }
    
    public static String buchongfu(String str){
        String [] strarr = new String[str.length()];
        for(int i = 0 ; i < str.length() ; i++){
            String newstr = str.charAt(i) +"";
            for(int j = i + 1; j < str.length() ; j ++){
                char ch = str.charAt(j);
                if(newstr.contains(ch+"")){
                    break;
                }else{
                    newstr += ch;
                }
            }
            strarr[i] = newstr;
        }
        int index = 0;
        for(int i = 0 ; i < strarr.length ; i ++){
            if(strarr[index].length() < strarr[i].length() )
                index = i;
        }
        return strarr[index];
    }
    
    public static void main(String args[]){
        /*
        Scanner scan = new Scanner(System.in);
        String str = null;
        str = scan.next();
        System.out.println(getsum(str));
        */
        /*
        Scanner scan  = new Scanner(System.in);
        int n = 0 ; 
        int  b = 0 ; 
        n = scan.nextInt();
        b = scan.nextInt();     
        System.out.println(getdiv(n,b));*/
        
        /*
        Scanner scan = new Scanner(System.in);
        int [] intarr = new int[90];
        int count = 0;
        int s = 0;
        System.out.println("输入");
        do{
            s = scan.nextInt();
            intarr[count] = s;
            count++;
        }while(s != 0);
        System.out.println("输出");
        for(int i = 0 ; i < count-1 ; i ++){
            System.out.println(step(intarr[i]));
        }*/
        
        /*
        Scanner scan = new Scanner(System.in);
        int num = scan.nextInt();
        System.out.println(primenum(num));*/
        
        //leapyear();
        
        /*
        Scanner scan = new Scanner(System.in);
        String str = scan.nextLine();
        System.out.println(otherstr(str));*/
        
        /*
        Scanner scan = new Scanner(System.in);
        int num = scan.nextInt();
        System.out.println(jiecheng(num));*/
        
        /*
        Scanner scan = new Scanner(System.in);
        int [] arr = new int[10];
        for(int i = 0 ; i < 10 ; i++){
            arr[i] = scan.nextInt();
        }
        arr = getswitch(arr);
        System.out.println(Arrays.toString(arr));
        */
        /*
        Scanner scan = new Scanner(System.in);
        int days = scan.nextInt();
        scan.close();
        System.out.println(eatpeach(days));
        */
        
        //System.out.println(replaceAB("1213","2a"));
        
        //System.out.println(kaisacode("T"));
        
        //System.out.println(miaoshu("01:10:10"));
        //System.out.println(miaoshu("12:05:05"));
        //System.out.println(buchongfu("pwwkew"));
        
        
    }
    
    
}

上一篇 下一篇

猜你喜欢

热点阅读