文章会有【原创】或者【转载】标示,部分来自Google Baidu的学习结果 {Java/PHP/Python/Ruby/Go}

Java 在学习四十九【原创】  


Java浙大版:


XX寸转里面


package coreJava;


import java.util.Scanner;


public class Test25 {


private static Scanner in;


public static void main(String[] args) {

int foot; //

int inch; //

int height; // 身高

in = new Scanner(System.in);

foot = in.nextInt();

inch = in.nextInt();

height = (int) ((foot + inch / 12.0) * 0.3048 * 100);

System.out.println("尺:" + foot + ", " + inch + " = " + height + "厘米");

}


}


模拟简单的地铁售票:

package coreJava;


import java.util.Scanner;


public class Test26 {


private static Scanner inScanner;


public static void main(String[] args) {

// TODO Auto-generated method stub

int blance = 0;

inScanner = new Scanner(System.in);

while (true) {

System.out.println("请输入票价:");

int amount = inScanner.nextInt();

blance += amount;

if (blance >= 5) {

System.out.println("地铁Java线Y->Z的票价:5,总共输入" + blance +"元,找零" + (blance - 5));

blance = 0;

}

}

}


}


判断数字的长度:

人的数数的思维是从左往右,计算机可以从右往左(/10) == 0

package coreJava;


import java.util.Scanner;


public class Test27 {


private static Scanner in;


public static void main(String[] args) {

in = new Scanner(System.in);

int count = 0;

System.out.println("请输入数字:");

int number = in.nextInt();

int n = number;

while (number > 0) {

number = number / 10;

count += 1;

}

System.out.println("Num:" + n + "的长度:" + count);

}


}


算平均数


变量 -》算法-》流程图-》程序;

让用户输入一系列的正整数,输入-1j结束


package coreJava;


import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;


public class Test28 {

private static Scanner in;


public static void main(String[] args) {

int count = 0, sum = 0, number = 0;

List<Integer> numberList = new ArrayList<Integer>();

in = new Scanner(System.in);

number = in.nextInt();

while (number != -1) {

sum += number;

count += 1;

numberList.add(number);

number = in.nextInt();

}

if (sum > 0) {

System.out.println("输入的数字:" + numberList.toString());

System.out.println("输入的总数:" + sum + ", 平均数:" + (float) sum / count);

}

}


}