标签:
1 package cn.bdqn.com; 2 3 import java.util.Scanner; 4 5 public class Jisaunqi { 6 int num1; 7 int num2; 8 int jieguo; 9 public void show(){ 10 Scanner input=new Scanner(System.in); 11 String fuhao1=input.next(); 12 char fuhao2=fuhao1.charAt(0); 13 14 switch(fuhao2){ 15 case ‘+‘: 16 jieguo=num1+num2; 17 break; 18 case ‘-‘: 19 jieguo=num1-num2; 20 break; 21 case ‘*‘: 22 jieguo=num1*num2; 23 break; 24 case ‘/‘: 25 jieguo=num1*num2; 26 } 27 System.out.println(num1+fuhao1+num2+"="+jieguo); 28 } 29 public static void main(String[] args) { 30 Scanner input=new Scanner(System.in); 31 Jisaunqi ji=new Jisaunqi(); 32 System.out.println("请输入第一个数"); 33 ji.num1=input.nextInt(); 34 System.out.println("请输入第二个数"); 35 ji.num2=input.nextInt(); 36 System.out.println("请输入运算符"); 37 ji.show(); 38 39 40 } 41 42 }
package cn.bdqn.com; public class Autolion { String color="黄色"; public void run(){ System.out.println("正在以0.1米/秒的速度向前奔跑."); } public String bark(){ String sound="大声吼叫"; return sound; } public String getColor(){ return color; } public String showLion(){ return "这是一个"+getColor()+"的玩具狮子!"; } public static void main(String[] args) { Autolion lion=new Autolion(); String info=lion.showLion(); System.out.println(info); lion.run(); System.out.println(lion.bark()); } }
标签:
原文地址:http://www.cnblogs.com/WuXuanKun/p/5342052.html