(2.1.24)Scanner控制台输入

import java.awt.List;
import java.util.ArrayList;
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
    	
        Scanner scanner = new Scanner(System.in);
        
        int count = scanner.nextInt();
        int num=0;
        
        int [] n = new int[100];
        
        ArrayList<String> Having=new ArrayList<String>();
        ArrayList<String> Wanting=new ArrayList<String>();
        
        scanner.nextLine();
        scanner.useDelimiter("\n");
        
        for (int i = 0; i <count; i++) {
        	
            
            String string=scanner.nextLine();
            String []strings=string.split("\t");
            
            for(int j=0;j<strings.length;j++){
            	if(!strings[j].equals(" ")){
            	  if(j==0)	n[i]=Integer.parseInt(strings[0]);
            	  if(j==1) {
            		  String [] havs=strings[1].split(",");
            		  for(String s:havs){
            			  Having.add(s);
            		  }
            	  }
            	  
            	  if(j==2) {
            		  String [] wans=strings[2].split(",");
            		  for(String s:wans){
            			  Wanting.add(s);
            		  }
            	  }
            	}
            		
            }
        }
        
        for(String s:Having){
        	if(Wanting.contains(s))
        		num++;
        }
        System.out.println(num);

        
       /* 3
        123 1001,1002 1003
        127  1100
        128 1003*/
    }
}


import java.util.Scanner;

public class Main {

	public static void main(String args[]) {
		Scanner cin = new Scanner(System.in);

		int a, b;
		double d;

		while (cin.hasNext()) {
			if (cin.hasNextInt()) {
				a = cin.nextInt();
				System.out.println(new java.text.DecimalFormat("#.00")
						.format(Math.abs(a)));
			} else if (cin.hasNextDouble()) {
				d = cin.nextDouble();
				System.out.println(new java.text.DecimalFormat("#.00")
						.format(Math.abs(d)));
			}

		}
	}
}


import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
/**
 * Target:
 * Author:YHF
 * Cin:
 * Cout:
 * Test: Nor:
 *       Bor:
 *       Err:
 */
public class asd
{
    public static void main(String args[])
    {
        Scanner cin = new Scanner(System.in);
        
        int a, b;
        int i=0;
        int Az[] = new int[10];
        
        String string;
        String Sz[]= new String[10];
        
        while(cin.hasNext())
        {
            a = cin.nextInt();
            b = cin.nextInt();
            
            System.out.println(a + b);
            
            /*string=cin.next();
            
            while(i<10)
            {
             Az[i]=cin.nextInt();
             i++;
             }
            
            i=0;
            while(i<10)
            {
            	Sz[i]=cin.next();
             i++;
             }
            
            System.out.println(a + b);
            System.out.println(string);
            
            for (int s : Az) {
                System.out.print(s);
            }
            
            for (String s : Sz) {
                System.out.print(s);
            }*/
        }
    }
}


import java.util.Scanner;


public class sada {

	public static void main(String args[]) {
		
		
		Scanner cin = new Scanner(System.in);
		int a, b;
		boolean isHave=false;
		double d;

		while (cin.hasNext()) {
				a = cin.nextInt();
				b = cin.nextInt();
				
				for(int i=a;i<b+1;i++){
					if(isDaffodilNumber(i)){
						System.out.println(i+" ");
						isHave=true;
					}
				}
				if(!isHave) System.out.println("no");
			
		}
	}
	
	 // 用于判断一个整数是否是水仙花数  
    public static boolean isDaffodilNumber(int i) {  
        boolean flag = true;  
  
        int a = i / 100; // 取得百位数  
        int b = (i / 10) % 10; // 取得十位数  
        int c = i % 10; // 取得个位数  
        /* 
         * if ((Math.pow(a, 3) + Math.pow(b, 3) + Math.pow(c, 3)) != i) {// 若各位数字立方和不等于该数本身 
         *       flag = false;// 返回false  
         * } 
         */  
        if (a * a * a + b * b * b + c * c * c != i) {// 若各位数字立方和不等于该数本身  
            flag = false;//返回false  
        }  
        return flag;  
    }  

	
}




你可能感兴趣的:((2.1.24)Scanner控制台输入)