Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unused variable warnings #32

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

public class Variables {

@SuppressWarnings("unused")
public static void main(String[] args) {
String name; // declaration
name = "Kaz"; // initialization
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@

public class FirstHalf {

@SuppressWarnings("unused")
public static void main(String[] args) {
String str1 = "WooHoo"; // should print "Woo"
String str2 = "HelloThere"; // should print "Hello"
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@

public class WithoutEnd {

@SuppressWarnings("unused")
public static void main(String[] args) {
String str1 = "Hello"; // should print "ell"
String str2 = "java"; // should print "av"
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@

public class Initialize {

@SuppressWarnings("unused")
public static void main(String[] args) {
boolean isRaining = false;
double price = 5.68;
18 changes: 12 additions & 6 deletions src/com/codefortomorrow/beginner/chapter4/examples/Arithmetic.java
Original file line number Diff line number Diff line change
@@ -4,21 +4,27 @@ public class Arithmetic {

public static void main(String[] args) {
// addition
int a = 5 + 1; // a has the value 6
int a = 5 + 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we still keep the comment?

Suggested change
int a = 5 + 1;
int a = 5 + 1; //a has value 6

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I deleted the comments because if you run the program the results are printed anyway (I added print statements).

System.out.println("a is " + a);

// subtraction
double b = 25.6 - 90; // b has the value 64.4
double b = 25.6 - 90;
System.out.println("b is " + b);

// multiplication
int c = 12 * 4; // c has the value 48
int c = 12 * 4;
System.out.println("c is " + c);

// integer division
int d = 10 / 3; // d has the value 3
int d = 10 / 3;
System.out.println("d is " + d);

// double division
double e = 10.0 / 3; // e has the value 3.3333333...
double e = 10.0 / 3;
System.out.println("e is " + e);

// modulus
int f = 10 % 3; // f has the value 1
int f = 10 % 3;
System.out.println("f is " + f);
}
}
Original file line number Diff line number Diff line change
@@ -3,12 +3,23 @@
public class AugmentedAssignment {

public static void main(String[] args) {
int a = 1;
int a = 10;
System.out.println("1. a is " + a);

a += 1; // equivalent to a = a + 1;
System.out.println("2. a is " + a);

a -= 2; // equivalent to a = a - 2;
System.out.println("3. a is " + a);

a *= 3; // equivalent to a = a * 3;
System.out.println("4. a is " + a);

// NOTE: In this case, we are doing integer division
a /= 4; // equivalent to a = a / 4;
System.out.println("5. a is " + a);

a %= 5; // equivalent to a = a % 5;
System.out.println("6. a is " + a);
}
}
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

public class InitializeArray {

@SuppressWarnings("unused")
public static void main(String[] args) {
// declare an array - can be initialized later
// with either of the initialization methods below
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

public class WrapperClasses {

@SuppressWarnings("unused")
public static void main(String[] args) {
// auto-boxing (int to Integer)
Integer intObject = 2;
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
Create a UML diagram for the Account class.
*/

@SuppressWarnings("unused")
public class Account {

private String name;