0
点赞
收藏
分享

微信扫一扫

关于我用Java答洛谷看似很简单的编程题

import java.util.Scanner;
public class algorithm {
    public static void main(String[] args) {
        algorithm a=new algorithm();
        Scanner s=new Scanner(System.in);
        int q=s.nextInt();
        while(q!=0) {
            switch (q) {
                case 1:
                    a.method1();
                    break;
                case 2:
                    a.method2();
                    break;
                case 3:
                    a.method3();
                    break;
                case 4:
                    a.method4();
                    break;
                case 5:
                    a.method5();
                    break;
                case 6:
                    a.method6();
                    break;
                case 7:
                    a.method7();
                    break;
                case 8:
                    a.method8();
                    break;
                case 9:
                    a.method9();
                    break;
                case 10:
                    a.method10();
                    break;
                case 11:
                    a.method11();
                    break;
                case 12:
                    a.method12();
                    break;
                case 13:
                    a.method13();
                    break;
                case 14:
                    a.method14();
                    break;

                default:
                    break;

            }
          q=s.nextInt();
        }
    }
    void method1()
    {
        System.out.println("I love Luogu!");
    }
    void method2()
    {
        System.out.printf("%d %d",6,4);
    }
    void method3()
    {
        System.out.printf("%d\n%d\n%d\n",14/4,12,14%4);
    }
    void method4()
    {
        System.out.printf("%.3f",500.0/3);
    }
    void method5()
    {
        System.out.println(15);
    }
    void method6()
    {
        System.out.println(Math.sqrt(117));
    }
    void method7()
    {
System.out.printf("%d\n%d\n%d\n",110,90,0);
    }
    void method8()
    {
      double pi=3.141593F;
      System.out.printf("%f\n%f\n%f\n",2*pi*5.0,pi*25.0,(double)4/3*1.0*pi*125.0);
    }
    void method9()
    {
        int x=1;
        for (int i=0;i< 3;i++){
        x=2*(x+1);
        }
        System.out.println(x);
    }
    void method10()
    {
       System.out.println(9);
    }
    void method11()
    {
      System.out.println(100.0/3);
    }
    void method12()
    {
System.out.printf("%d\n%c\n",('M'-'A'+1),'Z'-8);
    }
    void method13()
    {
        float pi=3.141593F;
        double v1,v2;
        double x=(double)4/3;
        v1=x*pi*64;
        v2=x*pi*1000;

        System.out.printf("%d",(int)Math.pow((v1+v2),1.0/3));
    }
    void method14()
    {
     System.out.println(50);
    }
}

6 8 11 题均因为精度问题迟迟得不到正确输出 …

举报

相关推荐

0 条评论