import java.util.Scanner; public class TestCircle { public static void main(String[] args) { Scanner s = new Scanner(System.in); Circle c = new Circle(); System.out.print("请输入圆半径:"); c.radius = s.nextDouble(); System.out.println("圆半径为:" c.getRadius()); System.out.println("圆周长为:" c.findGirth()); System.out.println("圆面积为:" c.findArea()); } } class Circle{ double radius;//半径 public double findGirth() {//计算周长 return 3.14*radius*2; } public double findArea() {//计算面积 return 3.14*radius*radius; } public double getRadius() { return radius; } public void setRadius(double radius) { this.radius = radius; } } ,下面我们就来说一说关于java计算圆的面积周长?我们一起去了解并探讨一下这个问题吧!

java计算圆的面积周长(Java练习求圆的周长)

java计算圆的面积周长

求圆的周长、面积

import java.util.Scanner; public class TestCircle { public static void main(String[] args) { Scanner s = new Scanner(System.in); Circle c = new Circle(); System.out.print("请输入圆半径:"); c.radius = s.nextDouble(); System.out.println("圆半径为:" c.getRadius()); System.out.println("圆周长为:" c.findGirth()); System.out.println("圆面积为:" c.findArea()); } } class Circle{ double radius;//半径 public double findGirth() {//计算周长 return 3.14*radius*2; } public double findArea() {//计算面积 return 3.14*radius*radius; } public double getRadius() { return radius; } public void setRadius(double radius) { this.radius = radius; } }

现在已知数组int[] arr = {12,34,465,3,45}; 将最大值和最小值的位置进行交换

/* * 现在已知数组int[] arr = {12,34,465,3,45}; * 将最大值和最小值的位置进行交换 */ public class Test { public static void main(String[] args) { int[] arr = {12,34,456,3,45}; System.out.print("arr[]:"); for(int i = 0; i<arr.length; i ) { System.out.print(arr[i] " "); } System.out.println(); //max,min int maxIndex = 0; int minIndex = 0; for(int i = 1; i<arr.length; i ) { if(arr[maxIndex] < arr[i]) { maxIndex = i; } if(arr[minIndex] > arr[i]) { minIndex = i; } } System.out.println("maxIndex:" maxIndex " " "minIndex:" minIndex); int a = arr[maxIndex]; arr[maxIndex] = arr[minIndex]; arr[minIndex] = a; // System.out.print("交换后arr[]:"); for(int i = 0; i<arr.length; i ) { System.out.print(arr[i] " "); } System.out.println(); } }

运行结果

arr[]:12 34 456 3 45 maxIndex:2 minIndex:3 交换后arr[]:12 34 3 456 45