package pr;
/*
* 编程实现两个整数交换位置,例如:int x = 6,y = 9,交换后 x = 9,y = 6。(易)
* @author administrator
* @date 2020/9/10
* */
public class Zuoye_1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int x=6;//任意整数
int y=9;//任意整数
int t;//中间变量
System.out.println("初始的x="+x+"\t"+"初始的y="+y);
//+:串起来
//交换位置
t = x;
x = y;
y = t;
System.out.println("交换后的x="+x+"\t"+"交换后的y="+y);
}
}
package pr;
/*
* 将华氏温度转化成摄氏温度。公式为:C=(5/9)*(F-32),其中F为华氏温度,C为摄氏温度。请根据给定的华氏温度输出对应的摄氏温度。
* @author administrator
* @date 2020/9/16
* */
public class Zuoye_2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
double F = 58;//华氏温度
double C;//摄氏温度
C = (5.0/9)*(F - 32);
System.out.println(C);
}
}
package pr;
/*
* 4、已知圆的半径,求圆的面积。(易)
* @author :administrator
* @date:2020/9/17
* */
public class Zuoye_4 {
public static void main(String[] args) {
// TODO Auto-generated method stub
double r = 5.5;
final double Pai = 3.1415926;
double s;
s = Pai * r *r;
/*
* 【强制转换】
* float r = (float)3.3
* float r = 3.3f
* */
System.out.println("半径:"+r);
System.out.println("圆的面积:"+s);
//syso (alt +/)
}
}
package pr;
/*
* 两个数比较大小,输出较大值。(易)【法2看test3.java,test4.java,test8.java】
* @author:administrator
* @date:2020/9/18
* */
public class Zuoye_5 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int num1 = 5;
int num2 = 7;
int max;
max = num1>num2? num1:num2;
System.out.println(max);
}
}
package pr;
public class test3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int num1 = 4;
int num2 = 6;
int max;
max = num1; //假设max为num1
if(num2 > max) {
max = num2;
}
System.out.println(num1+"和"+num2+"中"+"最大值为:"+max);
}
}
package pr;
/*
* 6、两个数比较大小,输出最大值。(较易)
* @date :2020/9/18
* */
public class test4 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int num1 = 4;
int num2 = 6;
int max;
if(num1>num2) {
max = num1;
}else {
max = num2;
}
System.out.println(num1+"和"+num2+"中"+"最大值为:"+max);
}
}
package pr;
/*
* 两个整数比较大小
* */
public class test8 {
//自定义方法【设计方法】
public static int max(int x,int y){
// int result;
// if(x > y) {
// result = x;
// }else {
// result = y;
// }
if(x > y) {
return x;
}
return y;
// return result;
}
//【调用】
public static void main(String[] args) {
// TODO Auto-generated method stub
int x = 4;
int y = 6;
int m;
m = max(x,y);//【调用方法】
System.out.println(m);
}
}
package pr;
import java.util.Scanner;
/*
* 8、判断某个整数是否为水仙花数。(水仙花数是一个三位数,该数各位的立方和等于该数本身。例如153是一个水仙花数,因为153 = 13 + 53 + 33)(较易)
* @author:administrator
* @date :2020/9/18
*
* */
public class Zuoye_8 {
public static void main(String[] args) {
// TODO Auto-generated method stub
@SuppressWarnings("resource")
Scanner scan = new