Java高手,快来帮帮我吧,明天交作业啊啊~-帮帮高手

天之醉 10-13 19:04:10 93

public class testjava {
final float PI=3.14f;
public void test1(int x)
{
if(x%2==0)
{
System.out.println(x+"是偶数");
}
else
{
System.out.println(x+"数");
}
}
public float getC(float r)
{
return (2*r*PI);
}
public int getChecgji(int n)
{
int tem=1;
for(int i=1;i<=n;i++)
{
tem=tem*i;
}
return tem;
}
public static void main(String[]args)
{
testjava obj=new testjava();
obj.test1(9);
float f1= obj.getC(4.5f);
int a= obj.getChecgji(3);
System.out.println("圆的周长"+f1);
System.out.println(3+"的阶乘为:"+a);
}
}

import java.text.DecimalFormat;
public class Test {
//第一
public static void checkNumber(int x){
if(x%2 != 0){
System.out.println(x+"是奇数");
}else{
System.out.println(x+"是偶数");
}
}
//第二题
public static double getGirth(float r){
//格式化数字,结果保留
DecimalFormat df = new DecimalFormat("
.##");
return Double.parseDouble(df.format(Math.PI * 2*r));
}
//第三题
public static int getFactorial(int n){
if(n==0 || n==1){
return n;
}else{
return n*getFactorial(n-1);
}
}
public static void main(String[] args){
checkNumber(1);
System.out.println(getGirth(1.3f));
System.out.println(getFactorial(4));
}
}

import java.util.Scanner;
public class Test1{
private static Scanner input;
public static void main(String args[]){
a = new Test1().one(input.nextInt());
}
public void one(int x){
if (x%2!=0)
System.out.println("数");
else
System.out.println("是偶数");
}
}
剩2题都跟差不多

1.import javax.swing.JOptionPane;
class A
{
public static void main(String[] args)
{
String str=JOptionPane.showInputDialog("请你要判断的数字");
int x;
x=Integer.parseInt(str);
if(x<=0)
{
System.out.println("你输入的不对");
}
else
{
if(x%2==0)
{
System.out.println("你输入的是偶数");
}
else
{
System.out.println("你输入的是奇");
}
}
}

}