Java基础(程序设计基础过关题库)

本文深入探讨Java编程基础知识,涵盖关键概念与实战题目,帮助读者巩固Java程序设计能力。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

outside-R

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值