目录
09: 写一个程序,输出类似09:03:12的时间格式,需要判断输入的数字是否符合实际情况,比如小时数就不能大于24,如果大于24就提示输入错误;分钟数和秒数不能大于60,如果大于60就提示输入错误。
如果能构建三角形,提示是直角三角形还是等边三角形等腰三角形还是普通三角形;
11:随机输入一个字母,如果是大写字母就转化为小写字母输出;如果是小写字母就转化为大写字母输出。
12:使用if结构实现学习成绩>=90分的同学用A表示,60-89分之间的用B表示,60分以下的用C表示。
13:使用条件结构实现:岳灵珊同学参加到Java的学习,他父亲岳不群和母亲宁中则承诺:
如果:b2-4ac>0,则有两个解;b2-4ac=0,则有一个解;b2-4ac<0,则无解;
09: 写一个程序,输出类似09:03:12的时间格式,需要判断输入的数字是否符合实际情况,比如小时数就不能大于24,如果大于24就提示输入错误;分钟数和秒数不能大于60,如果大于60就提示输入错误。
package WorkDemo2;
import java.util.Scanner;
public class DemoText2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入1-12之间的小时数:");
int hour = sc.nextInt();
System.out.println("请输入1-24之间的分钟数:");
int minute = sc.nextInt();
System.out.println("请输入1-24之间的秒数:");
int second = sc.nextInt();
if (hour >12 || hour<1 || minute >60 || minute<1 || second>60 || second<1){
System.out.println("输入错误,请检查一下重新输入");
}
if (hour<10){
System.out.print("0"+hour+":");
}else
System.out.println(hour+":");
if (minute <10){
System.out.print("0"+minute+":");
}else
System.out.print(minute+":");
if (second<10){
System.out.print("0"+second);
}else
System.out.print(second);
System.out.println();
}
}
10: 有3个整数,给出提示信息:
能否创建三角形;
如果能构建三角形,提示是直角三角形还是等边三角形等腰三角形还是普通三角形;
最后输出三角形面积;
这个代码不是很好,其中的三角形运算公式应该是:海伦公式:
s=Math.sqrt(p*(p-a)*(p-b)*(p-c))
package WorkDemo2;
import java.util.Scanner;
public class DemoText3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入三角形的三条边:");
System.out.println("请输入第一条边的值:");
int one = sc.nextInt();
System.out.println("请输入第二条边的值:");
int two = sc.nextInt();
System.out.println("请你输入第三条边的值:");
int three = sc.nextInt();
if (one+two<three){
System.out.println("你输入的三条边构不成三角形,请重新输入");
}else if(one==two || two==three || three==one){
System.out.print("这是等腰三角形:");
if(one == two){
double number=Math.sqrt(Math.pow(two, 2)-Math.pow((three/2.0),2));
System.out.println("三角形的面积是:"+((three*number)/2));
}else if(one == three){
double number=Math.sqrt(Math.pow(three, 2)-Math.pow((two/2.0),2));
System.out.println("三角形的面积是:"+((two*number)/2));
}else{
double number=Math.sqrt(Math.pow(three, 2)-Math.pow((one/2.0),2));
System.out.println("三角形的面积