Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Напишите метод, который будет увеличивать заданный элемент массива на 10% */
- class numsum {
- private double nums[];
- numsum (int size) {
- nums = new double[size];
- double k = 1.0;
- for (int i=0; i<nums.length; i++) {
- nums[i] = k;
- k += 1.0;
- }
- }
- void show () {
- for (int j=0; j<nums.length; j++)
- System.out.print(nums[j] + " ");
- System.out.println();
- }
- void change (int p) {
- try {
- nums[p] *= 1.1;
- } catch (ArrayIndexOutOfBoundsException e) {
- System.out.println("[change-index is out of array size]");
- }
- }
- }
- //comment 1 string above+below - would be 1 class instead of 2
- class test {
- public static void main(String args[]) {
- numsum ob1 = new numsum(10);
- ob1.show();
- ob1.change(5);
- ob1.show();
- numsum ob2 = new numsum(5);
- ob2.show();
- ob2.change(5); //would lead to exception
- ob2.change(2);
- ob2.show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement