Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Reference static fields from the class not the object instance#12

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
SleekPanther wants to merge2 commits intojsquared21:master
base:master
Choose a base branch
Loading
fromSleekPanther:master
Open
Show file tree
Hide file tree
Changes fromall 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
8 changes: 4 additions & 4 deletionsExercise_09/Exercise_09_05/Exercise_09_05.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,16 +21,16 @@ public static void main(String[] args) {

// Display the current year, month, and day in format Mth/Day/Year
System.out.print("\nCurrent year, month, and day in format Mth/Day/Year: ");
System.out.println(calender.get(calender.MONTH) + "/" +
calender.get(calender.DAY_OF_MONTH) + "/" + calender.get(calender.YEAR));
System.out.println(calender.get(GregorianCalendar.MONTH) + "/" +
calender.get(GregorianCalendar.DAY_OF_MONTH) + "/" + calender.get(GregorianCalendar.YEAR));

// Set elapsed time since January 1, 1970 to 1234567898765L
calender.setTimeInMillis(1234567898765L);

// Display the year, month and day
System.out.print("\nElapsed time since January 1, 1970 set to " +
"1234567898765L in format Mth/Day/Year: ");
System.out.println(calender.get(calender.MONTH) + "/" +
calender.get(calender.DAY_OF_MONTH) + "/" + calender.get(calender.YEAR));
System.out.println(calender.get(GregorianCalendar.MONTH) + "/" +
calender.get(GregorianCalendar.DAY_OF_MONTH) + "/" + calender.get(GregorianCalendar.YEAR));
}
}
37 changes: 22 additions & 15 deletionsExercise_19/Exercise_19_03/Exercise_19_03.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
/*********************************************************************************
* (Distinct elements in ArrayList) Write the following method that returns a new *
* ArrayList. The new list contains the non-duplicate elements from the original *
* list. *
* *
* public static <E> ArrayList<E> removeDuplicates(ArrayList<E> list) *
*********************************************************************************/
/**************************************************************************************
* (Distinct elements in ArrayList) Write the following method that returns a new *
* ArrayList. The new list contains the non-duplicate elements from the original list. *
* *
* public static <E> ArrayList<E> removeDuplicates(ArrayList<E> list) *
**************************************************************************************/
import java.util.ArrayList;

public class Exercise_19_03 {
/** Removes duplicate elements from an array list */
public static <E extends Comparable<E>>
ArrayList<E> removeDuplicates(ArrayList<E> list) {
for (int i = 0; i < list.size() - 1; i++) {
for (int j = i + 1; j < list.size(); j++) {
if (list.get(i).compareTo(list.get(j)) == 0)
list.remove(j);
public static <E extends Comparable<E>> ArrayList<E> removeDuplicates(ArrayList<E> list) {
ArrayList<E> newList = new ArrayList<E>();
if(!list.isEmpty()){
newList.add(list.get(0));//adds 1st item from reference list
for (int i = 1; i < list.size(); i++) {//loop starts from 1
boolean shouldAddToNewList = true;
for (int j = 0; j < newList.size(); j++) {
if (list.get(i).compareTo(newList.get(j)) == 0){
shouldAddToNewList = false;
}
}
if(shouldAddToNewList){
newList.add(list.get(i));
}
}
}
returnlist;
}
returnnewList;
}
}

[8]ページ先頭

©2009-2025 Movatter.jp