0923-----homework

  1 package com.kai.li.HomeWork0923;
  2
  3 /**
  4   *work class for all the class
  5   */
  6 public class HomeWork0923{
  7
  8     /**
  9       *main fuction for all the text
 10       */
 11     public static void main(String[] args){
 12         //questions of part 1
 13         for(int i=0;i<4;i++){
 14             int  k;
 15             switch(i){
 16                 case 0:
 17                     try{
 18                         int zero=0;
 19                         k=911/zero;
 20                         break;
 21                     }catch(ArithmeticException e){
 22                         System.out.println(e.getMessage());
 23                     }catch(Exception e){
 24                         e.printStackTrace();
 25                         System.out.println(e.getMessage());
 26                     }
 27                 case 1:
 28                     try{
 29                         int[] b=null;
 30                         k = b[0];
 31                         break;
 32                     }catch(NullPointerException e){
 33                         System.out.println(e.getMessage());
 34                     }catch(Exception e){
 35                         e.printStackTrace();
 36                         System.out.println(e.getMessage());
 37                     }
 38                 case 2:
 39                     try{
 40                         int c[]=new int[2];
 41                         k = c[9];
 42                         break;
 43                     }catch(ArrayIndexOutOfBoundsException e){
 44                         System.out.println(e.getMessage());
 45                     }catch(Exception e){
 46                         e.printStackTrace();
 47                         System.out.println(e.getMessage());
 48                     }
 49                 case 3:
 50                     try{
 51                         char ch = "abc".charAt(99);
 52                         break;
 53                     }catch(StringIndexOutOfBoundsException e){
 54                         System.out.println(e.getMessage());
 55                     }catch(Exception e){
 56                         e.printStackTrace();
 57                         System.out.println(e.getMessage());
 58                     }
 59             }
 60         }
 61         //questions of part 2
 62         Bank bank=new Bank(100);
 63         try{
 64             bank.withDrawal(150);
 65         }catch(InsufficientFundsException e){
 66             e.printStackTrace();
 67         }catch(NagativeFundsException e){
 68             e.printStackTrace();
 69         }
 70         bank=new Bank(100);
 71         try{
 72             bank.withDrawal(-15);
 73         }catch(NagativeFundsException e){
 74             e.printStackTrace();
 75         }catch(InsufficientFundsException e){
 76             e.printStackTrace();
 77         }
 78         //questions of part 3
 79         InterfaceX ix=()->{};
 80         ix.forl(‘a‘,26);
 81         ix.forl(‘A‘,26);
 82     }
 83 }
 84 /**
 85   *this example is texted of exception
 86   */
 87 //define the class bank ,it has some functions with text
 88 class Bank{
 89     private double balance;
 90     Bank(){
 91         this.balance=0;
 92     }
 93     Bank(double balance){
 94         this.balance=balance;
 95     }
 96     public double getBalance(){
 97         return this.balance;
 98     }
 99     public void withDrawal(double dAmount) throws InsufficientFundsException,NagativeFundsException{
100         if(balance<dAmount)
101             throw new InsufficientFundsException();
102         if(dAmount<0)
103             throw new NagativeFundsException();
104         this.balance-=dAmount;
105     }
106 }
107 //define the first exception by self
108 class InsufficientFundsException extends Exception{
109     @Override
110     public void printStackTrace(){
111         super.printStackTrace();
112         System.out.println("------------");
113     }
114 }
115 //define the seconde exception by self
116 class NagativeFundsException extends Exception{
117     @Override
118     public void printStackTrace(){
119         super.printStackTrace();
120         System.out.println("||||||||||||");
121     }
122 }
123 /**
124   *define a function interface
125   *it is created for the lembda
126   */
127 @FunctionalInterface
128 interface InterfaceX{
129     void printLetter();
130     default public void forl(int a,int b){
131         for(int i=a;i<a+b;i++){
132             System.out.print((char)i+" ");
133         }
134         System.out.println();
135     }
136 }
时间: 2024-10-26 20:39:21

0923-----homework的相关文章

HDU 1789 Doing Homework again(贪心)

Doing Homework again Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every teacher gives him a deadline of handing in the homework. If Ignatius hands in the homework after the deadlin

uva 1489 - Math teacher&#39;s homework(数位dp)

题目链接:uva 1489 - Math teacher's homework 题目大意:给定n,k,以及序列m1,m2,-,mn, 要求找到一个长度为n的序列,满足0<=xi<=mi, 并且x1XORx2XOR-XORxn=k 解题思路:数位dp,在网上看了别人的代码,高大上... 假设有二进制数 k : 00001xxxx mi:0001xxxxx, 那么对于xi即可以满足任意的x1XORx2XOR-XORxi?1XORxi+1XOR-XORxn,根据这一点进行数位dp. dp[i][j]

HDU 1074 Doing Homework 状压DP

Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every teacher gives him a deadline of handing in the homework. If Ignatius hands in the homework after the deadline, the teacher will r

HDU 1789 Doing Homework again

在我上一篇说到的,就是这个,贪心的做法,对比一下就能发现,另一个的扣分会累加而且最后一定是把所有的作业都做了,而这个扣分是一次性的,所以应该是舍弃扣分小的,所以结构体排序后,往前选择一个损失最小的方案直接交换就可以了. #include<stdio.h> #include<iostream> #include<string.h> #include<algorithm> using namespace std; struct HomeWork { int de

[2016-03-28][HDU][1074][Doing Homework]

时间:2016-03-28 18:46:36 星期一 题目编号:[2016-03-28][HDU][1074][Doing Homework] 题目大意:给定n门科作业的期限时间和完成耗时,每科每超过一天就扣一份,求最少扣分数 分析:n只有15,二进制枚举,状态压缩,枚举每种科目完成的状态,更新下一个状态,求最小值 #include <cstring> #include <cstdio> using namespace std; const int maxstu = 1 <&

Homework (7th,Mar.)

第一题: 1 /* 2 定义一个水果类(fruit),水果类中有 3 属性:颜色(color).价格(price).重量(weigth), 4 再定义一个<测试类>, 5 创建一个苹果(apple)的对象, 颜色是"红色",价格是5.5,重量10g. 6 然后再创建一个香蕉(banana)的对象,颜色是"黄色",价格是4.2,重量5g. 7 最后输出:苹果的颜色.价格.重量. 8 香蕉的颜色.价格.重量. 9 */ 10 package Homework

hdu 5298 Solid Geometry Homework(几何)

题目链接:hdu 5298 Solid Geometry Homework 每个圈或者是平面将划分出两个区域,每次把一边区域取反即可.最后判断一下是否满足. #include <cstdio> #include <cstring> #include <vector> #include <algorithm> using namespace std; const int maxn = 3000; typedef long long ll; struct Poi

HDU 1074 Doing Homework(状压dp)

Doing Homework Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6299    Accepted Submission(s): 2708 Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he has a l

HDU1789Doing Homework again(贪婪)

HDU1789Doing Homework again(贪心) 题目链接 题目大意:给你n们作业的最后期限和过了这个期限没做须要扣的分数.问如何安排能够使得扣分最少. 解题思路:贪心,将扣分多的作业排在前面,扣分同样的依照最后期限前的排前面,然后用一个数组来表示第i天是否有安排.每次都将第i个作业放到它的最后期限的那天完毕,但假设这一天被占了,那么就仅仅能往前移动,找空暇的天.假设一直找到了0.那么说明这个作业是无法按时完毕了,就加上分数.假设某项作业完毕的最后期限比n还大,那么这个作业一定是能

Doing Homework 状态压缩DP

Doing Homework 题目抽象:给出n个task的name,deadline,need.  每个任务的罚时penalty=finish-deadline;   task不可以同时做.问按怎样的顺序做使得penalty最小.同时输出顺序.如果有多个满足条件的顺序,按字典序输出. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #inc