Java 作业题 2

package Test;
import java.util.Scanner;
import java.text.DecimalFormat; 
import java.util.Random;

public class Main {
    static DecimalFormat  df  = new DecimalFormat("######0.00");  
    static double pft;static int all,month;
    static String value(int i)
    {
        double ans = all;
        
        for(int i1 =1; i1 <=i;i1++)
        {
            ans =  ans + ans*pft/1200;
        }
        return df.format(ans);
    }
    
    
    public static void main(String[] args) {
        
        @SuppressWarnings("resource")
        Scanner input=new Scanner(System.in);
        System.out.println("-------------Java homework 3rd 1.----------");    
        
        System.out.println("-----输入总数");                
        all = input.nextInt(); 
        
        System.out.println("-----输入年利率");    
        pft = input.nextDouble(); 
        
        System.out.println("-----输入月份");    
        month = input.nextInt(); 
        
        System.out.println("Month	  CD value");
        for (int i = 1; i <= month ;i++)
        {
            if (i < 10 )
                System.out.println( i + "	  "+ value(i) );    
            else if(i<100)
                System.out.println( i + "	  " +value(i) );    
            else
                System.out.println( "error : month >= 100 " );    
        }
        
        System.out.println("-------------Java homework 3rd 2.----------");    
        
        System.out.println("-----因为是随机过程 所以此程序运行2次 方便观察");    
        Random rand = new Random();
        
        for(int k = 1;k <= 5;k++)
        {
            System.out.println("第"+ k + "次试验");    
            
            int point1 = rand.nextInt(6) + 1;
            int point2 = rand.nextInt(6) + 1;
            int point = point1+point2;
            System.out.println("You rolled "+ point1 +" + " + point2);    
            if (point == 2 || point ==3|| point == 12 )
                System.out.println("You lose");    
            if (point == 7 || point ==11 )
                System.out.println("You win");    
            else 
            {
                System.out.println("point is" + point);    
                int point3,point4,pointt1;
                do {
                    point3 = rand.nextInt(6) + 1;
                    point4 = rand.nextInt(6) + 1;
                    pointt1 = point3+point4;
                    
                        System.out.println("You rolled " + point3+ " + " + point4);    
                        
                }while(pointt1!=7 && pointt1 != point);
                
                if(pointt1 == 7)
                    System.out.println("You lose");    
                if(pointt1 == point)
                    System.out.println("You win");    
        }

        
            
        }
                     
        
    }
    
}

基本是体力活 

原文地址:https://www.cnblogs.com/ranzhong/p/14142651.html