第二次Java作业
1.编写一个程序,定义圆的半径,求圆的面积.
public class testhello {
/**
* @param args
*/
public static void main(String[] args) {
double S;
int R=5;
S=3.14*(R*R);
System.out.println(S);
// TODO Auto-generated method stub
}
}
2.华氏温度和摄氏温度互相转换,从华氏度变成摄氏度你只要减去32,乘以5再除以9就行了,将摄氏度转成华氏度,直接乘以9,除以5,再加上32即行。(知识点:变量和运算符综合应用)
double hua=50;
//计算它对应的摄氏度
//输出摄氏度是xxxxx
public class testhello {
/**
* @param args
*/
public static void main(String[] args) {
double hua;
double she;
hua=50;
she=(hua-32)*5/9;
hua=she*9/5-32;
System.out.println(she);
// TODO Auto-generated method stub
}
}
double she=30;
//计算它对应的华氏度
//输出
public class testhello {
/**
* @param args
*/
public static void main(String[] args) {
double hua;
double she;
she=30;
hua=she*9/5-32;
she=(hua-32)*5/9;
System.out.println(hua);
// TODO Auto-generated method stub
}
}
public class testhello {
/**
* @param args
*/
3.已知a,b均是整型变量,写出将a,b两个变量中的值互换的程序。(知识点:变量和运算符综合应用)
int a=5,b=8;
//借助一个c交换a b 中的变量
public static void main(String[] args) {
int a=5;
int b=8;
int c;
a=c=5;
c=5;
b=a=8;
c=b=5;
System.out.println(a);
System.out.println(b);
// TODO Auto-generated method stub
}
}
4.定义一个任意的5位整数,将它保留到百位,无需四舍五入(知识点:变量和运算符综合应用)
12345 12300
public class testhello {
/**
* @param args
*/
public static void main(String[] args) {
int a=15789;
int s;
int d;
s=a/100;
d=s*100;
System.out.println(d);
// TODO Auto-generated method stub
}
}
public class testhello {
/**
* @param args
*/
5.输入一个0~1000的整数,求各位数的和,例如345的结果是3+4+5=12注:分解数字既可以先除后模也可以先模后除(知识点:变量和运算符综合应用)
public static void main(String[] args) {
int ge;
int shi;
int bai;
int a=598;
int b;
ge=a%10;
shi=a/10%10;
bai=a/100;
b=ge+shi+bai;
System.out.println(b);
// TODO Auto-generated method stub
}
}
public class testhello {
/**
* @param args
*/
6.定义一个任意的大写字母A~Z,转换为小写字母(知识点:变量和运算符综合应用)
定义一个任意的小写字母a~z,转换为大写字母
每一个字符都对应一个asc码 A--65 a---97 大写和它的小写差32
public static void main(String[] args) {
char v='d';
System.out.println((char)(v-32));
char c='D';
System.out.println((char) (c+32));
// TODO Auto-generated method stub
}
}