1. 程式人生 > >2017.12.1T19_B2_1zuoye

2017.12.1T19_B2_1zuoye

12.1 bre ble con imp ava 基本 param als


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));
}



**********************************************************8


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);

********************************************

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("\n");
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("\n");
System.out.println("第六題");
System.out.println("******************************");
System.out.println("\n");
Hero hero = new Hero();
hero.show2();

2017.12.1T19_B2_1zuoye