求一个简单的JAVA程序
7个回答
展开全部
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,"您的体重正常,请继续保持!");
}
}
}
}
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.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<Point> points = null;
MyFrame(String s) {
super(s);
points = new ArrayList<Point>();
setLayout(null);
setBounds(200, 200, 500, 500);
setBackground(new Color(204, 204, 255));
setVisible(true);
addMouseListener(new Moniter());
}
public void paint(Graphics g) {
Iterator<Point> i = points.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();
}
}
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<Point> points = null;
MyFrame(String s) {
super(s);
points = new ArrayList<Point>();
setLayout(null);
setBounds(200, 200, 500, 500);
setBackground(new Color(204, 204, 255));
setVisible(true);
addMouseListener(new Moniter());
}
public void paint(Graphics g) {
Iterator<Point> i = points.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 <chars.length; i++){
count[chars[i] - 'a']++;
}
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 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 <chars.length; i++){
count[chars[i] - 'a']++;
}
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!");
}
}
public static void main(String[] args){
System.out.print("HelloWorld!");
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
需要关于什么的?QQ349409
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询