zoukankan      html  css  js  c++  java
  • 蓝桥网试题 java 入门训练 圆的面积

    -----------------------------------------------------------------------------------------------------

    这个题其实没有一点的难度,只是对printf这个输出方法的使用

    -----------------------------------------------------------------------------------------------------

    算法

     

    import java.util.Scanner;
    public class Main {
    	public static void main(String[] args) {
    		int n = new Scanner(System.in).nextInt();
    		System.out.printf("%.7f",Math.PI*n*n);
    	}
    }
    

      -----------------------------------------------------------------------------

    printf()方法里的常用格式和C语言中的用差不多一样的

    int i = 1234;

    double d = 321.654;

    String s = "hello!";

    System.out.printf("%f",d);//"f"表示格式化输出浮点数。

    System.out.printf("%10.4f",d);//"19.4"中的10表示输出的长度(符号,小数点也算位数),2表示小数点后的位数。

     System.out.printf("%+9.2f",d);//"+"表示输出的数带正负号。  

    System.out.printf("%-9.4f",d);//"-"表示输出的数左对齐(默认为右对齐)。

    System.out.printf("%+-9.3f",d);//"+-"表示输出的数带正负号且左对齐。   

    System.out.printf("%d",i);//"d"表示输出十进制整数。   

    System.out.printf("%o",i);//"o"表示输出八进制整数(注意是小写字母"o")。   

    System.out.printf("%x",i);//"x"表示输出十六进制整数。(大小写不分)   

    System.out.printf("%#x",i);//"#x"表示输出带有十六进制标志的整数。 

    System.out.printf("输出一个浮点数:%f,一个整数:%d,一个字符串:%s",d,i,s);//可以输出多个变量,注意顺序。

    System.out.printf("字符串:%2$s,%1$d的十六进制数:%1$#x",i,s);//"X$"表示第几个变量。

     

  • 相关阅读:
    Leetcode Reverse Words in a String
    topcoder SRM 619 DIV2 GoodCompanyDivTwo
    topcoder SRM 618 DIV2 MovingRooksDiv2
    topcoder SRM 618 DIV2 WritingWords
    topcoder SRM 618 DIV2 LongWordsDiv2
    Zepto Code Rush 2014 A. Feed with Candy
    Zepto Code Rush 2014 B
    Codeforces Round #245 (Div. 2) B
    Codeforces Round #245 (Div. 2) A
    Codeforces Round #247 (Div. 2) B
  • 原文地址:https://www.cnblogs.com/loveluking/p/6031661.html
Copyright © 2011-2022 走看看