import javax.swing.JOptionPane;
public class test {
public static void main(String[] args) {
while(JOptionPane.showConfirmDialog(null, "确认要开始测试么")==0) {
double height=Double.parseDouble(JOptionPane.showInputDialog("请输入身高"));
double weight=Double.parseDouble(JOptionPane.showInputDialog("请输入体重"));
double a=weight/(height*height);
if (a>25) {
JOptionPane.showMessageDialog(null,"您的体重偏重哦,请注意饮食习惯.");
}
if (a<18.5) {
JOptionPane.showMessageDialog(null,"您的体重偏瘦,请多多锻炼身体!");
}
if(a>=18.5&&a<=25) {
JOptionPane.showMessageDialog(null,"您的体重正常,请继续保持!");
}
}
}
}
你这个是用来计算体重指数的。单位很重要啊。下面的程序身高单位是厘米,体重是公斤
import java.util.Scanner;
public class ABC {
public static void main(String[] args) {
String choice = "Y";
Scanner scanner = new Scanner(System.in);
while(choice.equalsIgnoreCase("Y")){
System.out.println("Press 'Y' to start testing, 'N' to cancel!");
choice = scanner.next().trim();
if(choice.equalsIgnoreCase("N")){
break;
}
System.out.print("Please input height: ");
float height = scanner.nextFloat()/100;//单位是厘米,必须除以100转化为米
System.out.print("Please input weight: ");
double weight = scanner.nextFloat();
double average = weight / (height * height);
if(average > 25){
System.out.println("A little fat");
}else if(average < 18.5){
System.out.println("A little thin");
}else{
System.out.println("Healthy");
}
}
}
}
----------------
Press 'Y' to start testing, 'N' to cancel!
y
Please input height: 173
Please input weight: 85
A little fat
Press 'Y' to start testing, 'N' to cancel!
y
Please input height: 173
Please input weight: 62
Healthy
Press 'Y' to start testing, 'N' to cancel!
y
Please input height: 173
Please input weight: 35
A little thin
Press 'Y' to start testing, 'N' to cancel!
n
import java.awt.*;
import java.util.*;
import java.awt.event.*;
import java.awt.Point;
public class MyMouseAdapter {
public static void main(String[] args) {
new MyFrame("draw ...");
}
}
class MyFrame extends Frame {
ArrayList
MyFrame(String s) {
super(s);
points = new ArrayList
setLayout(null);
setBounds(200, 200, 500, 500);
setBackground(new Color(204, 204, 255));
setVisible(true);
addMouseListener(new Moniter());
}
public void paint(Graphics g) {
Iterator
while(i.hasNext()) {
Point p = i.next();
g.setColor(Color.BLUE);
g.fillOval(p.x, p.y, 10, 10);
}
}
public void addPoint(Point p) {
points.add(p);
}
}
class Moniter extends MouseAdapter {
public void mousePressed(MouseEvent e) {
MyFrame f = (MyFrame)e.getSource();
f.addPoint(new Point(e.getX(), e.getY()));
f.repaint();
}
}
public class Test1 {
public static void main(String[] args){
char[] chars = new char[100];
for(int i = 0; i < chars.length; i++){
chars[i] = RandomCharacter.getRandomLowerCaseLetter();
}
System.out.println("随机的字母排序输出:");
displayArray(chars);
int[] count = countLetter(chars);
System.out.println();
System.out.println("字母出现的次数及字母顺序排序:");
displayCount(count);
}
private static void displayCount(int[] count) {
for(int i = 0; i < count.length; i++){
if((i+1) % 10 == 0 )
System.out.println(count[i] + " " + (char)(i + 'a'));
else
System.out.print(count[i] + " " +(char)(i + 'a') + " ");
}
}
private static int[] countLetter(char[] chars) {
int[] count = new int[26];
for(int i = 0; i
}
return count;
}
private static void displayArray(char[] chars) {
for(int i = 0; i < chars.length; i++){
if((i + 1) % 20 == 0)
System.out.println(chars[i]+" ");
else
System.out.print(chars[i]+" ");
}
}
}
public class HelloWorld{
public static void main(String[] args){
System.out.print("HelloWorld!");
}
}
需要关于什么的?QQ349409