A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© why910107 中级黑马   /  2016-6-14 21:29  /  1772 人查看  /  9 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

1.键盘输入10个数,放到数组中
        a.        去除该数组中大于10的数
        b.        将该数组中的数字写入到本地文件number.txt中
       
2.map中有如下数据(电话号=套餐价格)
        [13265477888=168,15241698745=11,13699989898=20,1898686666=120]
        在ip为127.0.0.1数据库名为stdb,连接数据库的用户名和密码为:admin和123456中有一个numinfo表相关字段为(id,iphonenum,tomoney)(15分)
        (1)将map中的手机号码取出来打印到控制台上(3分)
        (2)判断map中所有的手机号在numinfo表中是否存在存在则输出"该主机已登录"如果不存在将该号码及对应的套餐价格存入到numinfo表中.(12分)
    (map中的数据不需要修改)

9 个回复

倒序浏览
package com.love;
//这是点招题...看看你能理解多少吧!!!!!
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class Test06 {

        /**
         * @param args
         * @throws IOException
         */
        public static void main(String[] args) throws IOException {
                //定义一个长度为10的int数组
                int[] arr = new int[10];
                //创建Random类
                Random r = new Random();
                //求取1-100的随机数,不超过10个
                for (int i = 0; i < arr.length; i++) {
                        arr[i] = r.nextInt(100) + 1;
                }
                //用冒泡排序将此数组从小到大排序
                for (int i = 0; i < arr.length - 1; i++) {
                        for (int j = 0; j < arr.length - 1 - i; j++) {
                                if(arr[j] > arr[j + 1]) {
                                        int temp = arr[j];
                                        arr[j] = arr[j + 1];
                                        arr[j + 1] = temp;
                                }
                        }
                }
                //打印排序后的数组
                System.out.println(Arrays.toString(arr));
               
                //创建list集合
                ArrayList<Integer> list =  new ArrayList<>();
                //增强for循环,遍历该数组
                for (Integer integer : arr) {
                        //判断,如果数组中的值是大于50
                        if(integer >= 50) {
                                //就添加到list集合中
                                list.add(integer);
                        }
                }
                //打印list集合中的大于等于50的集合
                System.out.println(list);
               
                //创建map集合
                HashMap<Integer, Integer> map = new HashMap<>();
                //因为map是双列集合,所以定义一个变量存储在键中
                int count = 0;
                //增强for循环,遍历arr数组
                for (Integer integer : arr) {
                        //只要该数组中有小于50的数,就存在map集合中
                        if(integer < 50) {
                                map.put(count++, integer);
                        }
                }
                //增强for循环,变量map集合并打印输出
                for (Map.Entry<Integer, Integer> integer : map.entrySet()) {
                        System.out.print(integer.getValue() + " ");
                }
                //创建带缓冲的字符缓冲流
                BufferedWriter bw = new BufferedWriter(new FileWriter("aaa.txt"));
                //增强for循环,遍历数组
                for (Integer integer : arr) {
                        //将数组中的元素写到aaa.txt中
                        bw.write(integer + "");
                        //写出一个跨平台的回车换行
                        bw.newLine();
                }
                //关流
                bw.close();
               
        }

}
回复 使用道具 举报
666666666      
回复 使用道具 举报
public class Demo08 {
        public static void main(String[] args) throws IOException {
                int[] arr = new int[10];
                ArrayList<Integer> list = new ArrayList<>();
                Properties prop  = new Properties();
                //得到小于10的数组
                arr = arrs(arr,list);
                FileW(arr,prop);
        }
        //键盘录入10个数并存入数组
        public static int[] arrs(int[] arr,ArrayList<Integer> list) {
                Scanner sc = new Scanner(System.in);
                //录入10个数
                for(int i  = 0 ; i < arr.length;i++) {
                        System.out.println("请键盘录入第: " + (i+1) + "个数");
                        arr[i] = sc.nextInt();
                }
                //遍历数组把小于10 的全部放到list集合中
                for (int i : arr) {
                        if(i > 10) {
                                list.add(i);
                        }
                }
                //把list集合中元素放到数组中
                for (Integer num : list) {
                        for (Integer i : arr) {
                                i = num;
                        }
                }
                return arr;
        }
       
        public static void FileW(int[] arr,Properties prop) throws IOException {
                for (int i = 0; i < arr.length; i++) {
                        prop.setProperty(i + "", arr[i] + "");     
                }
                FileOutputStream fos  = new FileOutputStream("number.txt");
                prop.store(fos, "save arr");
                fos.close();
        }
}
回复 使用道具 举报
谢谢  知识点好多  我也练练
回复 使用道具 举报
我思路是一 、1.调用Scanner得到10个数2.遍历数组大于小于10的数数写到新数组中3.
回复 使用道具 举报
不错,借鉴一下
回复 使用道具 举报
自己琢磨啊,不能抄袭别人的
回复 使用道具 举报
都要用io流哦
回复 使用道具 举报
haojingwei310 发表于 2016-6-15 11:12
public class Demo08 {
        public static void main(String[] args) throws IOException {
                int[] arr = new ...

for (Integer i : arr) {
                                i = num;
                        }

增强for循环只能查看,不能增删改。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马