• 入门练习


    import java.util.Scanner;
    
    
    public class Main{
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		final double rate=8.25;
    		final int common=40;
    		double pay=0;
    		Scanner in=new Scanner(System.in);
    		System.out.println("请输入工作时间:");
    		int worktime=in.nextInt();
    		System.out.println("您的工作时间是:"+worktime);
    		if(worktime>=common)
    		{
    			pay=((worktime-common)*(rate*1.5)+common*rate);
    			
    			
    		}
    
    		else
    		{
    			pay=worktime*rate;
    		}
    		System.out.println("您的工资是:"+pay);
    		
    		
    		
    	}
    
    }
    

      注释:此代码用于计算工人工资

    import java.util.Scanner;
    
    
    public class Main {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
            System.out.println("你好");
            Scanner in =new Scanner(System.in);
    //        System.out.println("echo:"+in.nextLine());
    //        int amount=100;
            int amount;
            int price=0;
            System.out.println("price");
            System.out.println("你好,请输入票面:");
            amount=in.nextInt();
            System.out.println("你好,请输入金额:");
            price=in.nextInt();
            System.out.println(amount+"-"+price+"="+(amount-price));
            
    	}
    
    }
    

      注释:此代码用于店面找零

    import java.util.Scanner;
    
    
    public class Main {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
         //初始化
    		Scanner in=new Scanner(System.in);
    		int balance=0;
    		while(true)
    		{
    			System.out.println("请投币:");
    			int amount =in.nextInt();
    		    System.out.println(amount);
    		    balance=balance+amount;
    		    System.out.println(balance>=10);
    		    if(balance>=10)
    		    {
    		    	System.out.println("***********");
    		    	System.out.println("*java城际铁路专线*");
    		    	System.out.println("*无指定位置*");
    		        System.out.println("票价10元");
    		    	System.out.println("**********");
    		        System.out.println("找零:"+(balance-10)+"元");
    		        balance=0;
    		    }
    //		    else
    //		    {
    //		    	
    //		    	System.out.println("请继续投币,投入金额不足");
    //		    	
    //		    }
    //		    
    		    
    		    
    		    
    		}
    	    
    	}
    
    }
    

      

     注释:此代码为简单的购票系统的模型 

    import java.util.Scanner;
    
    
    public class Main {
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
            int foot;
            double inch;
            System.out.println(10/3);
            System.out.println(1.2+"-"+1.1+"="+(1.2-1.1));
            Scanner in=new Scanner(System.in);
            foot=in.nextInt();
            inch=in.nextDouble();
            System.out.println("foot="+foot+",inch="+inch);
            System.out.println((int)((foot+(double)(inch/12.0))*0.3048*100)+"cm");
            
    	}
    
    }
    

      注释:此代码是用于英尺和米的转换

      

    import java.util.Scanner;
    
    
    public class Main {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		Scanner in=new Scanner(System.in);
    		int number;
    		int sum=0;
    		int count=0;
    		System.out.println("请输入要求平均数的几个数(以-1结束):");
    		number=in.nextInt();
    		while(number!=-1)
    		{
    			sum=sum+number;
    			count++;
    			number=in.nextInt();
    		
    		}	
    			if(count>0)
    			{
    				System.out.println("average="+(double)sum/count);
    				
    			}
    				
    
    	}
    
    }
    

      

      注释:这是一个计算几个数的平均数问题

    import java.util.Scanner;
    
    
    public class Main {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		Scanner in=new Scanner(System.in);
    		int number=in.nextInt();
    		int count=0;
    		while(number>0)
    		{
    			number=number/10;
    			count=count+1;
    		}
    		System.out.println("count="+count);
    
    	}
    
    }
    

      注释:这是求随便输入一个数然后求出它是几位数

    import java.util.Scanner;
    
    
    public class qiantao1 {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated methodstub
    		int max=0;
    		System.out.println("请输入三个数");
    		Scanner in=new Scanner(System.in);
    		int x=in.nextInt();
    		int y=in.nextInt();
    		int z=in.nextInt();
    		if(x<y)
    		{
    			if(y<z)
    				max=z;
    			else
    				max=y;
    			
    			
    		}
    		else
    		{
    			if(x<z)
    				max=z;
    			else
    				max=x;
    			
    		}
    		System.out.println("max="+max);
    		
    		
    		System.out.println("下面进入switch case练习");
    		System.out.println("请输入一个数");
    		int type=in.nextInt();
    		switch(type)
    		{
    		case 1:
    			System.out.println("hello");
    		case 2:
    			System.out.println("你好");
    			break;
    		case 3:
    			System.out.println("晚上好");
    		case 4:
    			System.out.println("再见");
    			break;
    		default:
    			System.out.println("啊,什么呀");
    			break;
    		
    		
    		
    		
    		
    		
    		}
    		
    		
    		
    	}
    
    }
    

      注释;if语句的嵌套求三个数的最大值和switch 语句的运用

    总结:今天是刚刚学习java 感觉还可以,语言是相通的,语法都是差不多的。

  • 相关阅读:
    UESTC 250 windy数 数位dp
    hdu 3555 bomb 数位dp
    hdu 2089 不要62 数位dp入门
    poj 3740 Easy Finding 精确匹配
    codeforces 589F. Gourmet and Banquet 二分+网络流
    hdu 3572 Escape 网络流
    hdu 3572 Task Schedule 网络流
    POJ 1823 Hotel 线段树
    2016年,机器学习和人工智能领域有什么重大进展?
    【由浅入深的VR技术之旅】初学VR要解决的三个核心技术问题
  • 原文地址:https://www.cnblogs.com/abtious/p/7182739.html
Copyright © 2020-2023  润新知