Scanner 输入


 1 import java.util.Scanner;
 2  
 3 public class gongzi{
 4        public static void main(String[] args){
 5        System.out.println("请输入基本工资: ");
 6        Scanner sc = new Scanner(System.in);
 7        double i = sc.nextDouble();
 8        double a = 1200.0;   
 9        double b = 750.0;
10        double sum = a + b + i;
11        System.out.println("该员工的工资细目为:");
12        System.out.println("基本工资为:  " + i);
13        System.out.println("物价津贴为:  " + a);
14        System.out.println("房租津贴为:  " + b);
15        System.out.println("员工薪水是:  " + sum);
16 }       
17 }

 

 1 import java.util.Scanner;
 2 
 3 public class chou{
 4 
 5        public static void main(String[] args){
 6        System.out.println("请输入4位会员卡号:");
 7        Scanner sc = new Scanner(System.in);
 8        int i = sc.nextInt();
 9        if(i >= 1000 && i <= 9999){
10        int a,b,c,d,sum;
11        a = i/1000; 
12        b = i/100%10;
13        c = i/10%10;
14        d = i%10;
15        sum = a + b + c + d;
16        System.out.println("会员卡号" + i +"各位之和:   " + sum);
17        }else {
18        System.out.println("您输入的卡号有误!");
19        }                  
20      }          
21 }

 

1.变量
  临时存放数据,方便以后再来使用,所以可以改变
  变量可以有多种类型: 基本数据类型: boolean(true,false),float,double,byte,char,int ,short,
                                    long
                      引用数据类型: 类,接口,数组

2.运算符 : + , - ,* ,/,%, ++,--;

3.数据转换:大类型向小类型转换要强制转,有精度丢失;  
           小类型向大类型没问题
4.键盘的输入: import java.util.Scanner;
             Scanner sc = new Scanner(System.in);
             int i = sc.nextInt();
             double d = sc.nextDouble();
             String str = sc.nextLine();

 

posted @ 2012-10-19 10:03  邹晟  阅读(1197)  评论(0编辑  收藏  举报