没有合适的资源?快使用搜索试试~ 我知道了~
JAVA语言程序设计第六版编程答案第三章
5星 · 超过95%的资源 需积分: 9 5 下载量 67 浏览量
2011-09-16
08:04:30
上传
评论
收藏 10KB TXT 举报
温馨提示
试读
10页
JAVA语言程序设计第六版编程答案第三章
资源推荐
资源详情
资源评论
3_1
import javax.swing.JOptionPane;
public class Exercise3_1{
public static void main(String[] args){
double edge1 = Double.parseDouble(JOptionPane.showInputDialog(null,"输入第一条边长:"));
double edge2 = Double.parseDouble(JOptionPane.showInputDialog(null,"输入第二条边长:"));
double edge3 = Double.parseDouble(JOptionPane.showInputDialog(null,"输入第三条边长:"));
boolean isTriangle = isTriangle(edge1,edge2,edge3);
String output = "Can deges " + edge1 + " , " + edge2 + " and " + edge3 + " from a triangle? "+
isTriangle;
JOptionPane.showMessageDialog(null,output);
}
private static boolean isTriangle(double edge1,double edge2,double edge3){
double temp;
if(edge1<edge2){
temp = edge1;
edge1 = edge2;
edge2 = temp;
}
if(edge1<edge3){
temp = edge1;
edge1 = edge3;
edge3 = temp;
}
if(edge2<edge3){
temp = edge2;
edge2 = edge3;
edge3 = temp;
}
if(edge1<(edge2+edge3))
import javax.swing.JOptionPane;
public class Exercise3_1{
public static void main(String[] args){
double edge1 = Double.parseDouble(JOptionPane.showInputDialog(null,"输入第一条边长:"));
double edge2 = Double.parseDouble(JOptionPane.showInputDialog(null,"输入第二条边长:"));
double edge3 = Double.parseDouble(JOptionPane.showInputDialog(null,"输入第三条边长:"));
boolean isTriangle = isTriangle(edge1,edge2,edge3);
String output = "Can deges " + edge1 + " , " + edge2 + " and " + edge3 + " from a triangle? "+
isTriangle;
JOptionPane.showMessageDialog(null,output);
}
private static boolean isTriangle(double edge1,double edge2,double edge3){
double temp;
if(edge1<edge2){
temp = edge1;
edge1 = edge2;
edge2 = temp;
}
if(edge1<edge3){
temp = edge1;
edge1 = edge3;
edge3 = temp;
}
if(edge2<edge3){
temp = edge2;
edge2 = edge3;
edge3 = temp;
}
if(edge1<(edge2+edge3))
return true;
else
return false;
}
}
3_2
import javax.swing.JOptionPane;
public class Exercise3_2{
public static void main(String[] args){
int num = Integer.parseInt(JOptionPane.showInputDialog(null,"输入一个整数"));
String output = "Is " + num + " an even number? " +isEven(num);
JOptionPane.showMessageDialog(null,output);
}
private static boolean isEven(int num){
if(num % 2 ==0)
return true;
else
return false;
}
}
3_3
import javax.swing.JOptionPane;
public class Exercise3_3{
public static void main(String[] args){
int num = Integer.parseInt(JOptionPane.showInputDialog(null,"输入一个整数"));
String output = "Is " + num + " divisible by 5 and 6 ? "+ isDivisibleBoth(num) +
"\nIs " + num + " divisible by 5 or 6 ? "+ isDivisibleOr(num) +
"\nIs " + num + " divisible by 5 or 6 , but not both ? "+ isDivisible(num);
JOptionPane.showMessageDialog(null,output);
}
else
return false;
}
}
3_2
import javax.swing.JOptionPane;
public class Exercise3_2{
public static void main(String[] args){
int num = Integer.parseInt(JOptionPane.showInputDialog(null,"输入一个整数"));
String output = "Is " + num + " an even number? " +isEven(num);
JOptionPane.showMessageDialog(null,output);
}
private static boolean isEven(int num){
if(num % 2 ==0)
return true;
else
return false;
}
}
3_3
import javax.swing.JOptionPane;
public class Exercise3_3{
public static void main(String[] args){
int num = Integer.parseInt(JOptionPane.showInputDialog(null,"输入一个整数"));
String output = "Is " + num + " divisible by 5 and 6 ? "+ isDivisibleBoth(num) +
"\nIs " + num + " divisible by 5 or 6 ? "+ isDivisibleOr(num) +
"\nIs " + num + " divisible by 5 or 6 , but not both ? "+ isDivisible(num);
JOptionPane.showMessageDialog(null,output);
}
剩余9页未读,继续阅读
资源评论
- 许银灯2011-11-15只有第三章 不过确实可以编译
xiayizhanxinfu
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功