1.1定义圆的半径,求面积。
package wang; import java.util.Scanner; public class wang { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in); System.out.println("请输入圆的半径:"); float a = input.nextFloat(); double b = 3.14; System.out.println("圆的面积为:"+a*a*b); } }
2.华氏温度和摄氏混度互相转换,从华氏度变成摄民度你只要减去32,剩以5再除以9就行了,将摄氏度转成华氏度,直接乘以9,除以5,再加上32即行
package wang; import java.util.Scanner; public class wang { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("输入华氏温度:"); float hua = input.nextFloat(); System.out.println("转换为摄氏温度:"+(hua-32)*5/9); System.out.println("输入摄氏温度:"); float she = input.nextFloat(); System.out.println("转换为华氏温度:"+(she*9/5+32)); } }
3.已知a,b均是整型变量,写出将a,b两个变量中的值互换的程序。
package wang; import java.util.Scanner; public class wang { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("输入a的值:"); int a = input.nextInt(); System.out.println("输入b的值:"); int b = input.nextInt(); int c = a; a =b; b = c; System.out.println("a的值为:"+a+"\nb的值为:"+b); } }
4.定义一个任意的5位整数,将它保留到百位,无需四舍五入(知识点:变量和运算符综合应用)
package wang; import java.util.Scanner; public class wang { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("输入一个五位数:"); int h = input.nextInt(); System.out.println("保留到百位为:"+h/100*100); } }
5.输入一个0~1000的整数,求各位数的和,例如345的结果是3+4+512,注:分解数字既可以先除后模也可以先模后除(知识点:变量和运算符综合应用)
package wang; import java.util.Scanner; public class wang { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("输入一个0~1000"); int num = input.nextInt(); int ge = num%10; int shi = num/10%10; int bai = num/100; System.out.println("各位的和为"+(ge+shi+bai)); } }
6定义一个任意的大写字母A~Z,转换为小写字母(知识点:变量和运算符综合应用)
package wang; import java.util.Scanner; public class wang { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("输入任意一个大写字母:"); char da = input.next().charAt(0); char xiao = (char)((int)(da)+32); System.out.println("小写为:"+xiao); } }
7定义一个任意的小写字母a~z,转换为大写字母
package wang; import java.util.Scanner; public class wang { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("输入任意一个小写字母:"); char xiao = input.next().charAt(0); char da = (char)((int)(xiao)-32); System.out.println("小写为:"+da); } }