第一次作业
1. 定义圆形半径,求面积

2.华氏温度和摄氏温度互相转换,从华氏度变成摄氏度你只要减去32,乘以5再除以9就行了,将摄氏度转成华氏度,直接乘以9,除以5,再加上32即行


3.已知a,b均是整型变量,写出将ab两个变量中的值互换的程序。

4..定义一个任意的5位整数,将它保留到百位,无需四舍五入(知识点,变量和运算符综合应用

5..输入一个0 1000的整数,求各位的和,例345的结果是3+4+5= 12注:分解数字既可以先除后模也可以先模后除(如识点:变量和运算符综合应用

6.定义一个任意的大写字母A~Z,转换为小写字母(知识点,变量和运算符综合应用)

7.定义一个任意的小写字母a~z,转换为大写字母

import java.util.*;
public class 测试 {
public static void main(String[] args) { // Main方法 程序入口
select();
}
private static Scanner s = new Scanner(System.in);
public static void select() {
System.out.println("1.第一题");
System.out.println("2.第二题");
System.out.println("3.第三题");
System.out.println("4.第四题");
System.out.println("5.第五题");
System.out.println("6.第六题");
System.out.println("7.第七题");
System.out.println("8.退出系统");
System.out.println("请输入您的选项:");
int input = s.nextInt();
if (input == 1) {
first();
} else if (input == 2) {
second();
} else if (input == 3) {
thirdly();
} else if (input == 4) {
fourthly();
} else if (input == 5) {
fifth();
} else if (input == 6) {
sixth();
} else if (input == 7) {
seventh();
} else if (input == 8){
System.exit(0);
}
s.close();
}
public static void first() {
System.out.println("请输入半径的长度");
float r = s.nextFloat();
double area;
double pi=3.14;
area = pi*r*r;
System.out.println("圆的面积为:"+area);
select();
}
public static void second() {
System.out.println("1.华转摄");
System.out.println("2.摄转华");
int a = s.nextInt();
if( a == 1){
System.out.println("请输入您要转化的华氏度:");
float b = s.nextFloat();
float c;
c = (b-32)*5/9;
System.out.println("摄氏度为:"+c);
}else if(a == 2){
System.out.println("请输入您要转化的摄氏度:");
float b = s.nextFloat();
float c;
c = (b*9/5)+32;
System.out.println("华氏度为:"+c);
}
select();
}
public static void thirdly() {
double temp;
System.out.println("请输入第一个数:");
double a1 = s.nextDouble();
System.out.println("请输入第二个数:");
double a2 = s.nextDouble();
temp = a1;
a1 = a2;
a2 = temp;
System.out.println("第一个数:" + a1);
System.out.println("第二个数:" + a2);
select();
}
public static void fourthly(){
System.out.println("请输入一个五位数:");
int a = s.nextInt();
int b = a-(a%100);
System.out.println("保留到百位的结果:"+b);
select();
}
public static void fifth(){
System.out.println("请输入一个0`10000的数:");
int a = s.nextInt();
if (a<10){
System.out.println("各位数的和为:"+a);
}else if(10 <= a && a < 100){
int ge = a%10;
int shi = (a - ge)/10;
int sum = ge+shi;
System.out.println("各位数的和为:"+sum);
}else if(100<=a && a<1000){
int ge = a%10;
int shi = (a%100-ge)/10;
int bai = a/100;
int sum = ge+shi+bai;
System.out.println("各位数的和为:"+sum);
}if(1000<=a && a<10000){
int ge = a%10;
int shi = (a%100-ge)/10;
int bai = (a%1000-shi*10-ge)/100;
int qian = a/1000;
int sum = ge+shi+bai+qian;
System.out.println("各位数的和为:"+sum);
}if(a == 10000){
System.out.println("各位数的和为:"+1);
}
select();
}
public static void sixth(){
System.out.println("输入的字符串为:");
String str=s.next();
String strs ="";
for(int i =0; i<str.length();i++){
char ch = str.charAt(i);
if (ch>='a'&& ch<'z'){
ch = (char)((int)ch-32);
strs+=ch;
}
}
System.out.println("输出的字符串为:"+strs);
select();
}
public static void seventh(){
System.out.println("输入的字符串为:");
String str=s.next();
String strs ="";
for(int i =0; i<str.length();i++){
char ch = str.charAt(i);
if(ch>='A'&& ch<'Z'){
ch = (char)((int)ch+32);
strs+=ch;
}
}
System.out.println("输出的字符串为:"+strs);
select();
}
}

浙公网安备 33010602011771号