摄氏度转换为华氏度并弹窗提示###
import java.util.Scanner;
import javax.swing.JOptionPane;
public class Temperature {
public static void main(String[] args) {
String a = JOptionPane.showInputDialog("请输入摄氏度:");
double b = Double.parseDouble(a);
double c = b * 33.8;
JOptionPane.showMessageDialog(null,"华氏度:"+c);
}
}
输出3个数内最大的数###
import javax.swing.JOptionPane;
public class FindMaxDig {
public static void main(String[] args) {
String a=JOptionPane.showInputDialog("请输入第一个数");
String b=JOptionPane.showInputDialog("请输入第二个数");
String c=JOptionPane.showInputDialog("请输入第三个数");
int num1=Integer.parseInt(a);
int num2=Integer.parseInt(b);
int num3=Integer.parseInt(c);
int max = num1>num2?num1:num2;
max= max>num3?max:num3;
JOptionPane.showMessageDialog(null, "最大数值为:"+max);
}
}
三个数从小到大排序###
import java.util.Scanner;
public class Rank {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("请输入三个数字:");
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
if(a>b){
int d = a;
a=b;
b=d;
}
if(a>c){
int d = a;
a=c;
c=d;
}
if(b>c){
int d = b;
b=c;
c=d;
}
System.out.println(a+"\t"+b+"\t"+c);
//System.out.printf("%d\t%d\t%d\n", a, b, c);
sc.close();
}
}
计算圆的周长与面积###
import java.util.Scanner;
public class Round {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入圆的半径");
final double pi = 3.14;
int radii = sc.nextInt();
double perimeter = (pi * 2) * radii;
double area = pi * (radii * radii);
System.out.println("圆的周长是:" + perimeter + "\n" + "圆的面积是:" + area);
sc.close();
}
}
自动输出今天天星期几早餐该吃什么###
package Hello;
//星期135吃包子,246吃油条,星期天吃面。
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Scanner;
public class Breakfast {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Calendar cal = new GregorianCalendar();
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
if (dayOfWeek == 2) {
System.out.println("今天星期一:");
} else if (dayOfWeek == 3) {
System.out.println("今天星期二:");
} else if (dayOfWeek == 4) {
System.out.println("今天星期三:");
} else if (dayOfWeek == 5) {
System.out.println("今天星期四:");
} else if (dayOfWeek == 6) {
System.out.println("今天星期五:");
} else if (dayOfWeek == 7) {
System.out.println("今天星期六:");
} else {
System.out.println("今天星期天:");
}
sc.close();
switch (dayOfWeek) {
case '2':
case '3':
case '4':
System.out.print("今天早上吃包子");
break;
case '6':
System.out.print("今天早上吃面");
break;
default:
System.out.println("今天早上吃油条");
}
}
}