第一次实训作业
1 pqckage bbb;
public class java1{
public static void main(String[] args){
int a;
a=5;
if(a%2==0)
System.out.println("a为偶数");
else
System.out.println("a为奇数”);
}
}
2
package bbb;
imoort java.util.*;
public class JavaDemo {
public static void main(String[] args)
{
Scanner sc=new scanner(system.in);
final float PI = 3.1415f;
System.out.print("请输入半径:");
float r;
r = sc.nextFloat();
System.out.printf("面积为:"+PI*r*r);
}
}
3
import java.util.*;
public class java
{
public static void main(String[] args)
{
final float PI=3.14159f;
Scanner sc=new Scanner(System.in);
System.out.println("请输入一个整数:");
int a;
a=sc.nextInt();
System.out.println("加密后的整数是:"+(int)((a*10+5)/2+PI));
}
}
4
package bbb;
public class Chicken {
public static void main(String[] args) {
int x,y,z;
for(x=0;x<=14;x++)
for(y=0;y<=25;y++)
{
z=100-x-y;
if(x+y+z==100&&5*x+3*y+z/3.0==100)
System.out.println("公鸡"+x+"只,"+"母鸡"+y+"只,"+"小鸡"+z+"只");
}
}
}
5
public class shu {
public static void main(String[] args) {
int number;
int count = 0;
for(int i = 1; i<=4; i++)
for(int j =1; j<=4; j++)
for(int k = 1; k<=4; k++)
if(i != j && i != k && j!=k)
{
count++;
number = i*100+j*10+k;
System.out.println(number);
}
}
}
(6)
import java.util.*;
public class sushu {
public static void main(String[] args) {
int i=0;
Scanner reader = new Scanner(System.in);
int num;
num=reader.nextInt();
for(i=2;i<num;i++) {
if(num%i==0)
break;
if(num==i)
System.out.println(num+"为素数");
else
System.out.println(num+"不是素数");
}