diff --git a/ch_01/Exercise01_04.java b/ch_01/Exercise01_04.java index 8ab9c6e..c2aacb9 100644 --- a/ch_01/Exercise01_04.java +++ b/ch_01/Exercise01_04.java @@ -11,47 +11,10 @@ public class Exercise01_04 { public static void main(String[] args) { - int a = 2; - int b = 3; - int c = 4; - - for (int i = 0; i < 5; i++) { - if (i > 0) { - System.out.print("\n"); - } - for (int j = 0; j < 3; j++) { - - if (i == 0) { - if (j == 0) - System.out.print("a "); - if (j == 1) - System.out.print("a^2 "); - if (j == 2) - System.out.print("a^3"); - - } else if (i == 1) { - System.out.print("1 "); - } else if (i == 2) { - System.out.print(a + " "); - a *= 2; - - } else if (i == 3) { - System.out.print(b + " "); - b *= 3; - - } else { - System.out.print(c + " "); - c *= 4; - - } - - - } - - + int num = 4; + for (int row = 1; row <= num; row++) { + System.out.println(row + " " + row * row + " " + row * row * row); } - } - } diff --git a/ch_07/Exercise07_05.java b/ch_07/Exercise07_05.java deleted file mode 100644 index 68c80ff..0000000 --- a/ch_07/Exercise07_05.java +++ /dev/null @@ -1,48 +0,0 @@ -package ch_07; - -import java.util.Scanner; - -/** - * 7.5 (Print distinct numbers) Write a program that reads in ten numbers and - * displays the number of distinct numbers and the distinct numbers in their - * input order and separated by exactly one space (i.e., if a number appears - * multiple times, it is displayed only once). (Hint: Read a number and store - * it to an array if it is new. If the number is already in the array, ignore it.) - * After the input, the array contains the distinct numbers. - */ -public class Exercise07_05 { - public static void main(String[] args) { - Scanner input = new Scanner(System.in); - int[] nums = new int[10]; - - int checkNum = 0; - int counter = 0; - - System.out.print("Enter ten integers seperated by spaces: "); - - for (int i = 0; i < 10; i++) { - checkNum = input.nextInt(); - if (specialNum(nums, checkNum)) { - nums[counter] = checkNum; - counter++; - } - } - - System.out.println("The count of distinct numbers are " + counter); - System.out.print("The distinct numbers are"); - - for (int i = 0; i < nums.length; i++) { - if (nums[i] != 0) - System.out.print(" " + nums[i]); - } - System.out.println(); - } - - public static boolean specialNum(int[] a, int number) { - for (int i = 0; i < a.length; i++) { - if (a[i] == number) - return false; - } - return true; - } -} \ No newline at end of file