「Java转圈代码」原地转圈代码

博主:adminadmin 2022-11-23 08:03:06 53

今天给各位分享Java转圈代码的知识,其中也会对原地转圈代码进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

java 中怎么让位图围绕一个点转圈?

int a=0,b=0;//原点

Sin和Cos函数,可以得到圆上所有点,写个例子给你

int r=250;//半径

int time=0;

while(true)

{

time++;

int h = (Math.PI / 180) * 6 * times;

int X = a + Math.sin(h) * r;

int Y = b - Math.cos(h) * r;

}

X和Y是坐标

int类型可能会出问题,转换一下就行了

怎么用java实现转圈输出

我自己写的 放进去的时候把包名改下 类名记得一样

这个没有行列数限制,可以是长方形的,

如果要正方形的话,行列数设置成相等

package com.test;

public class Ddd {

public static void main(String[] args) {

int n = 9, m = 10;//n行数,m是列数

int num = 1;

int total = n * m;

int a[][] = new int[n][m];

int count = 0;

loop: for (;;) {

{

int i = count;

for (int j = count; j = m - count - 1; j++) {

a[i][j] = num;

num++;

if (num total) {

break loop;

}

}

}

{

int j = m - count - 1;

for (int i = count+1; i = n - count - 2; i++) {

a[i][j] = num;

num++;

}

if (num total) {

break loop;

}

}

{

int i = n - count - 1;

for (int j = m - count - 1; j = count ; j--) {

a[i][j] = num;

num++;

}

if (num total) {

break loop;

}

}

{

int j = count;

for (int i = n - count - 2; i = count + 1; i--) {

a[i][j] = num;

num++;

}

if (num total) {

break loop;

}

}

count++;

}

for (int[] b : a) {

for (int c : b) {

if (c 10) {

System.out.print(" " + c + " ");

} else {

System.out.print(c + " ");

}

}

System.out.println();

}

}

}

怎么用java写下面的代码?

按照题目要求编写的Circle类的Java程序如下(文件名Circle.java)

public class Circle{

private double radius;

Circle(){

radius=0;

}

Circle(double r){

radius=r;

}

double getRadius(){

return radius;

}

double getLength(){

return 2*Math.PI*radius;

}

double getArea(){

return Math.PI*radius*radius;

}

void disp(){

System.out.println("圆的半径为"+getRadius());

System.out.println("圆的周长为"+getLength());

System.out.println("圆的面积为"+getArea());

}

}

下面是Circle类的测试类Test(文件名Test.java 要运行需要和Circle.java放在同一包内)

public class Test{

public static void main(String[] args){

Circle c=new Circle(2.5);

c.disp();

}

}

关于Java转圈代码和原地转圈代码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

发布于:2022-11-23,除非注明,否则均为首码项目网原创文章,转载请注明出处。