码迷,mamicode.com
首页 > 编程语言 > 详细

java第五天之---方法与数组

时间:2017-06-26 12:37:08      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:str   blog   数组   span   code   void   image   another   键盘   

技术分享

案例一:从键盘输入两个数据,比较大小

import java.util.Scanner;
class FunctionTest {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    System.out.println("input a number:");
    int a = sc.nextInt();

    System.out.println("input another nuber:");
    int b = sc.nextInt();

    int result = Getmax(a,b);
    System.out.println("maxvalue:"+result);
  }
  public static int Getmax(int a,int b) {
    if(a > b) {
      return a;
    }else {
      return b;
    }
  }
}

执行结果:

D:\>java FunctionTest
input a number:
45
input another nuber:
88
maxvalue:88

案例二:比较键盘输入的两个数值是否相等

技术分享

技术分享

 

 

输出结果:

D:\java_code>java FunctionTest01
input a number:
88
input another nuber:
88
True or False: true

 #####################################################

技术分享

技术分享

输出结果:

D:\java_code>java FunctionTest02
input a number:
8
input another nuber:
8
********
********
********
********
********
********
********
********

 

java第五天之---方法与数组

标签:str   blog   数组   span   code   void   image   another   键盘   

原文地址:http://www.cnblogs.com/shanhua-fu/p/7079841.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!