如何根据字符串中的数字计算百分比?

时间:2019-11-30 23:12:31

标签: java arrays string floating-point stringtokenizer

*****-**大家好,我受困于我的课程,因为我无法根据总金额打印每种犯罪的百分比……有人可以帮助我吗?** *****

    public class corecode {
        @SuppressWarnings("resource")
        public static void main(String[] args) {
    //  Declaration of amount of crimes with postcodes//
    //  Crimes in order: Anti-Social, Bike Theft, Burglary, Arson or Damage, Drugs, Other Crime,  Other Theft, Weapon Possession, Public Order, Robbery, Shop lift, Theft from Person, Vehicle Crimes, Violence/Sexual Offence
                String[]E162= {"Royal Docks","E162","242","9","103","81","77","143","147","8","57","37","20","33","157","323","1437"};
                int[]NumerizedE162= new int[E162.length];
    // Scan of the INPUT Postcode by the user //        
        Scanner sc = new Scanner(System.in);
            System.out.println("Insert Postcode: \n");
    // Obtaining of INPUT Postcode in a string format // 
            String data = sc.next();
        int var1 = 0;
        int a = 1;
        float A;

    // Comparison of the INPUT Postcode with OUR list of Postcodes in the Area considered //
    // If INPUT Postcode is in the Area considered, Priniting Area & Postcode found & all the crimes in order //
        if( var1 == data.compareTo(E162[a])){
                    var1 = a;
                    System.out.println("Area: "+E162[0]);
                    System.out.println("Postcode: "+E162[var1]);
                    for(int count=0,count1=2; count1<NumerizedE162.length;count++) {
                        NumerizedE162[count1]= Integer.parseInt(E162[count1]);
                        A = NumerizedE162[count1]*(100/1437);
                        System.out.println(CRIMES[count]+E162[count1]+" "+A+"%");
                        count1++;
                    }
                    }

0 个答案:

没有答案