【实例简介】
5.1统计正数和负数的个数然后计算这些数的平均值
5.10找出能被5和6整除的数
5.11找出能被5或6整除,但不能被两者同时整除的数
5.12求满足n的平方大于12000的n的最小值
5.13求满足n的立方小于12000的n的最大值
5.14计算最大公约数
5.15显示ASCII码字符表
5.16找出一个整数的因子
5.16找出一个整数因子
5.17显示金字塔
5.18使用循环语句打印4个图案?
5.19打印金字塔形的数字?
【实例截图】
【核心代码】
package nameyu;
import java.util.Scanner;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.print("Enter an integer, the input end if it is 0:");
Scanner input=new Scanner(System.in); // int n=input.nextInt();
double sum=0,ave;
int positive=0,negative=0,count=0;
int n=input.nextInt();
while(n==0){
System.out.println("nonononono");
break;
}
while(n!=0){
sum =n;
count;
if(n>0){
positive ;
}else
negative ;
n=input.nextInt();
ave=sum/count;
System.out.println("The number of positives is " positive);
System.out.println("The number of negatives if " negative);
System.out.println("The total is " sum);
System.out.println("The average is " ave);
}
}
}