java程序设计教程修订版课后答案(java语言程序设计(第3版)第四章课后练习)

本文目录
java语言程序设计(第3版)第四章课后练习
public class TestAry{
public static void main(String arys){
int intAry ={1, 2, 3, 4, 5, 13};
Array ary = new Array(intAry);
System.out.println("Sum of the Ary is: " + ary.calcSum());
}
}
class Array {
private int intAry;
public Array() {
}
/**
* Constructor for Array
*/
public Array(int ary) {
this.intAry = ary;
}
public int calcSum(){
int sum = 0;
for(int i = 0; i 《 intAry.length; i++){
sum += intAry;
}
return sum;
}
}
求助JAVA程序设计答案 急!!!
1题:
public static void main(String args) throws Exception{
// TODO Auto-generated method stub
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入:");
char c;
int i=0;
try {
i=b.read(c);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String s=new String(c,0,i);
Num num=new Num();
num.show(s);
}
class Num{
public void show(String ss){
StringBuffer str=new StringBuffer(ss);
System.out.println("逆序的结果为:"+str.reverse());
}
}
2.题 类似第一题。只是用你到Math.PI把圆周率求出来算一下就可以了。
java 程序设计基础求答案
四 程序设计题
1 编写代码
import java.util.Scanner;
public class E {
public static void main(String args) {
Scanner sc=new Scanner(System.in);
System.out.println("请输入分数");
int score=sc.nextInt();
if(score》100 || score《0){
System.out.println("输入分数错误!");
return;
}
switch(score/10){
case 10:
case 9:System.out.println("优秀");break;
case 8:System.out.println("良好");break;
case 7:System.out.println("中等");break;
case 6:System.out.println("及格");break;
default:System.out.println("不及格");
}
}
}
运行结果
请输入分数
78
中等
2 编写代码
import java.util.Scanner;
public class EE {
public static void main(String args) {
Scanner sc=new Scanner(System.in);
System.out.println("请输入项数n");
int n=sc.nextInt();
int i=1;
double sum=0;
int t=1;
while(i《=n){
sum=sum+t*1.0/i;
i++;
t=-t;
}
System.out.println("1-1/2+1/3-1/4+...+1/n的值为"+sum);
}
}
运行结果
请输入项数n
5
1-1/2+1/3-1/4+...+1/n的值为0.7833333333333332

更多文章:
corrcoef函数(为什么matlab里corrcoef函数只能产生2×2的系数矩阵 求高手帮忙)
2026年1月20日 21:30
excel表格加减乘除函数公式(EXCEL中加法减法乘法除法怎么算啊!)
2025年11月13日 20:30
js字符串转date类型(js怎么把string转换成date)
2025年8月11日 06:00
onclick与click的区别(onclick和click的区别)
2025年5月31日 04:00
oracle触发器怎么设置(oracle apex 怎么设置触发器)
2025年8月13日 19:30
兼容织梦系统cms系统(什么是CMS系统目前流行的CMS系统主要有哪些各有哪些优缺点如何选择CMS系统拜托各位大神)
2025年10月5日 07:00
phpcmsv9最新利用工具(WampServer是一款WAMP软件包,该软件包由哪些软件整合而成)
2026年4月13日 18:15
写出在powerpoint中创建演示(阐述在PowerPoint中创建演示文稿的方法(至少三种))
2026年5月31日 02:30
word如何使用正则匹配(c#word查找用如何用正则表达式模糊匹配)
2025年6月14日 21:00
swift code 中国工商银行(中国工商银行的Swift code(银行国际代码)是什么)
2025年9月1日 20:45











