package com.whxiong.work01;
import java.util.Scanner;
public class Calculator {
Scanner input = new Scanner(System.in);
public void show() {
char Calculator;
double num = 0;
double num1 = 0;
System.out.println("请输入第一个整数:");
do {
if (input.hasNextInt() == false) {
System.out.println("输入错误!");
break;
}
if (input.hasNextInt() == true)
;
{
num = input.nextInt();
}
System.out.println("请输入第二个整数:");
if (input.hasNextInt() == false) {
System.out.println("输入错误!");
break;
}
if (input.hasNextInt() == true) {
num1 = input.nextInt();
}
System.out.println("请输入运算符号:+ - * /");
Calculator = input.next().charAt(0);
switch (Calculator) {
case '+':
System.out.println(num + "+" + num1 + "=" + (num + num1));
break;
case '-':
System.out.println(num + "-" + num1 + "=" + (num - num1));
break;
case '*':
System.out.println(num + "*" + num1 + "=" + (num * num1));
break;
case '/':
System.out.println(num + "/" + num1 + "=" + (num / num1));
break;
}
break;
} while (input.hasNextInt() == false);
*****************************************************
package com.whxiong.work01;
public class CurrentTime {
String year;
String mooth;
String date;
String hour;//小时
String minutes;//分钟
String second;//秒
public void show1(){
System.out.println("当前时间是:"+(year+mooth+date+hour+minutes+second));
}
***********************************************************
package com.whxiong.work01;
import java.util.*;
public class Hero {
Scanner input=new Scanner(System.in);
String heroName;
double heroLife;
String monsterName;//monster》》》》怪物
double monsterLife;//怪物生命
String monsterType;//怪物类型
String weaponsName;//weapons》》》》武器
double weaponsDamage;//damage》》》》攻击力,武器攻击力
public void show2() {
System.out.println("输入英雄姓名:");
heroName=input.next();
System.out.println("输入英雄生命值:");
heroLife=input.nextDouble();
System.out.println("输入怪物名字:");
monsterName=input.next();
System.out.println("输入怪物生命值:");
monsterLife=input.nextDouble();
System.out.println("输入怪物类型:");
monsterType=input.next();
System.out.println("输入武器名:");
weaponsName=input.next();
System.out.println("输入武器攻击力:");
weaponsDamage=input.nextDouble();
System.out.println("我是英雄,我的基本信息如下:");
System.out.println("姓名:"+heroName+",生命值:"+heroLife);
System.out.println("我是武器,我的基本信息如下:");
System.out.println("武器名:"+weaponsName+",攻击力:"+weaponsDamage);
System.out.println("我是怪物,我的基本信息如下:");
System.out.println("姓名:"+monsterName+",生命值:"+monsterLife+",类型:"+monsterType);
}
}******************************************************
package com.whxiong.work01;
public class Work01 {
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("第二题");
System.out.println("******************************");
Calculator calculator = new Calculator();
calculator.show();
System.out.println("
");
System.out.println("第三题");
System.out.println("******************************");
CurrentTime currentTime = new CurrentTime();
currentTime.year = "2015年";
currentTime.mooth = "5月";
currentTime.date = "12日";
currentTime.hour = "10点";
currentTime.minutes = "11分";
currentTime.second = "00秒";
currentTime.show1();
System.out.println("
");
System.out.println("第六题");
System.out.println("******************************");
System.out.println("
");
Hero hero = new Hero();
hero.show2();