SlideShare a Scribd company logo
1 of 7
Download to read offline
NumberList.java (implements the linked list)
public class NumberList{
Node first;
Node last;
public NumberList(){
first = null;
last = null;
}
public NumberList(Node node){
this.first = node;
this.last = node;
}
public boolean isEmpty(){
return first == null;
}
public void setLast(Node node){
this.last = node;
}
public void insert(Node node){
if (first==null){
this.first = node;
this.last = node;
}
else{
node.previous = this.last;
node.previous.next = node;
node.next = null;
this.last = node;
}
}
public boolean inList(String num){
Node l = first;
while (l.next != null){
if (l.number.equals(num)){
return true;
}
else{
l = l.next;
}
}
return false;
}
public void printList(){
Node l = first;
while(l.next!=null){
System.out.print(l.number+" ");
l = l.next;
}
System.out.println();
}
}
Node.java (implements a single node in the linked list; stores number and pointers)
public class Node{
String number;
Node previous;
Node next;
public Node(String num){
number = num;
previous = null;
next = null;
}
public Node(String num, Node p, Node n){
number = num;
previous = p;
next = n;
}
}
Main.java (contains the main method and the helper methods to solve the questions given)
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
public class Main{
static boolean checkHappiness(String num){
Node current = new Node(num, null, null);
NumberList numberList = new NumberList(current);
int len = num.length();
int resultant = 0;
for (int i=0; i happyNumbersfrom1to10000(){
ArrayList numbers = new ArrayList();
for (int j=0; j<10000; j++){
if (checkHappiness(String.valueOf(j+1))){
numbers.add(String.valueOf(j+1));
}
}
return numbers;
}
static void happyNumbersfrom9001to10000(){
for (int j=9001; j<=10000; j++){
//System.out.println(j);
if (checkHappiness(String.valueOf(j))){
System.out.println(String.valueOf(j));
}
}
}
static String getLargeHappyNumber(){
for (long i=10000000000000000000L; i<1000000000000000000000L; i++){
if (checkHappiness(String.valueOf(i))){
return String.valueOf(i);
}
return "-1";
}
}
static String getLargeUnhappyNumber(){
for (long i=10000000000000000000L; i<1000000000000000000000L; i++){
if (!checkHappiness(String.valueOf(i))){
return String.valueOf(i);
}
return "-1";
}
}
public static void main(String[] args){
happyNumbersfrom9001to10000();
System.out.println(happyNumbersfrom1to10000());
}
}
Solution
NumberList.java (implements the linked list)
public class NumberList{
Node first;
Node last;
public NumberList(){
first = null;
last = null;
}
public NumberList(Node node){
this.first = node;
this.last = node;
}
public boolean isEmpty(){
return first == null;
}
public void setLast(Node node){
this.last = node;
}
public void insert(Node node){
if (first==null){
this.first = node;
this.last = node;
}
else{
node.previous = this.last;
node.previous.next = node;
node.next = null;
this.last = node;
}
}
public boolean inList(String num){
Node l = first;
while (l.next != null){
if (l.number.equals(num)){
return true;
}
else{
l = l.next;
}
}
return false;
}
public void printList(){
Node l = first;
while(l.next!=null){
System.out.print(l.number+" ");
l = l.next;
}
System.out.println();
}
}
Node.java (implements a single node in the linked list; stores number and pointers)
public class Node{
String number;
Node previous;
Node next;
public Node(String num){
number = num;
previous = null;
next = null;
}
public Node(String num, Node p, Node n){
number = num;
previous = p;
next = n;
}
}
Main.java (contains the main method and the helper methods to solve the questions given)
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
public class Main{
static boolean checkHappiness(String num){
Node current = new Node(num, null, null);
NumberList numberList = new NumberList(current);
int len = num.length();
int resultant = 0;
for (int i=0; i happyNumbersfrom1to10000(){
ArrayList numbers = new ArrayList();
for (int j=0; j<10000; j++){
if (checkHappiness(String.valueOf(j+1))){
numbers.add(String.valueOf(j+1));
}
}
return numbers;
}
static void happyNumbersfrom9001to10000(){
for (int j=9001; j<=10000; j++){
//System.out.println(j);
if (checkHappiness(String.valueOf(j))){
System.out.println(String.valueOf(j));
}
}
}
static String getLargeHappyNumber(){
for (long i=10000000000000000000L; i<1000000000000000000000L; i++){
if (checkHappiness(String.valueOf(i))){
return String.valueOf(i);
}
return "-1";
}
}
static String getLargeUnhappyNumber(){
for (long i=10000000000000000000L; i<1000000000000000000000L; i++){
if (!checkHappiness(String.valueOf(i))){
return String.valueOf(i);
}
return "-1";
}
}
public static void main(String[] args){
happyNumbersfrom9001to10000();
System.out.println(happyNumbersfrom1to10000());
}
}

More Related Content

Similar to NumberList.java (implements the linked list)public class NumberLis.pdf

hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfarchgeetsenterprises
 
Link list part 2
Link list part 2Link list part 2
Link list part 2Anaya Zafar
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdffreddysarabia1
 
I will provide my LinkedList from my last lab.LinkedList.cpp~~~~.pdf
I will provide my LinkedList from my last lab.LinkedList.cpp~~~~.pdfI will provide my LinkedList from my last lab.LinkedList.cpp~~~~.pdf
I will provide my LinkedList from my last lab.LinkedList.cpp~~~~.pdffunkybabyindia
 
Note             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdfNote             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdfAnkitchhabra28
 
Create a new java class called ListNode. Implement ListNode as a gen.pdf
Create a new java class called ListNode. Implement ListNode as a gen.pdfCreate a new java class called ListNode. Implement ListNode as a gen.pdf
Create a new java class called ListNode. Implement ListNode as a gen.pdfmohamednihalshahru
 
In C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdfIn C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdfflashfashioncasualwe
 
Help I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdfHelp I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdfmail931892
 
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdfPROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdfclimatecontrolsv
 
How do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdfHow do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdffmac5
 
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdfHow do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdfmail931892
 
In an ancient land, the beautiful princess Eve had many suitors She d.pdf
In an ancient land, the beautiful princess Eve had many suitors She d.pdfIn an ancient land, the beautiful princess Eve had many suitors She d.pdf
In an ancient land, the beautiful princess Eve had many suitors She d.pdfezzi552
 
The LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfThe LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfmalavshah9013
 
Что нам готовит грядущий C#7?
Что нам готовит грядущий C#7?Что нам готовит грядущий C#7?
Что нам готовит грядущий C#7?Andrey Akinshin
 
There is something wrong with my program-- (once I do a for view all t.pdf
There is something wrong with my program-- (once I do a for view all t.pdfThere is something wrong with my program-- (once I do a for view all t.pdf
There is something wrong with my program-- (once I do a for view all t.pdfaashienterprisesuk
 
using set identitiesSolutionimport java.util.Scanner; c.pdf
using set identitiesSolutionimport java.util.Scanner;  c.pdfusing set identitiesSolutionimport java.util.Scanner;  c.pdf
using set identitiesSolutionimport java.util.Scanner; c.pdfexcellentmobilesabc
 
package singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfpackage singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfamazing2001
 
Java AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdfJava AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdfambersushil
 
Solve using Java programming language- ----------------------------.pdf
Solve using Java programming language-   ----------------------------.pdfSolve using Java programming language-   ----------------------------.pdf
Solve using Java programming language- ----------------------------.pdfaksahnan
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdffeelinggift
 

Similar to NumberList.java (implements the linked list)public class NumberLis.pdf (20)

hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdf
 
Link list part 2
Link list part 2Link list part 2
Link list part 2
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
 
I will provide my LinkedList from my last lab.LinkedList.cpp~~~~.pdf
I will provide my LinkedList from my last lab.LinkedList.cpp~~~~.pdfI will provide my LinkedList from my last lab.LinkedList.cpp~~~~.pdf
I will provide my LinkedList from my last lab.LinkedList.cpp~~~~.pdf
 
Note             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdfNote             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdf
 
Create a new java class called ListNode. Implement ListNode as a gen.pdf
Create a new java class called ListNode. Implement ListNode as a gen.pdfCreate a new java class called ListNode. Implement ListNode as a gen.pdf
Create a new java class called ListNode. Implement ListNode as a gen.pdf
 
In C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdfIn C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdf
 
Help I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdfHelp I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdf
 
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdfPROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
 
How do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdfHow do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdf
 
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdfHow do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
 
In an ancient land, the beautiful princess Eve had many suitors She d.pdf
In an ancient land, the beautiful princess Eve had many suitors She d.pdfIn an ancient land, the beautiful princess Eve had many suitors She d.pdf
In an ancient land, the beautiful princess Eve had many suitors She d.pdf
 
The LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfThe LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdf
 
Что нам готовит грядущий C#7?
Что нам готовит грядущий C#7?Что нам готовит грядущий C#7?
Что нам готовит грядущий C#7?
 
There is something wrong with my program-- (once I do a for view all t.pdf
There is something wrong with my program-- (once I do a for view all t.pdfThere is something wrong with my program-- (once I do a for view all t.pdf
There is something wrong with my program-- (once I do a for view all t.pdf
 
using set identitiesSolutionimport java.util.Scanner; c.pdf
using set identitiesSolutionimport java.util.Scanner;  c.pdfusing set identitiesSolutionimport java.util.Scanner;  c.pdf
using set identitiesSolutionimport java.util.Scanner; c.pdf
 
package singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfpackage singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdf
 
Java AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdfJava AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdf
 
Solve using Java programming language- ----------------------------.pdf
Solve using Java programming language-   ----------------------------.pdfSolve using Java programming language-   ----------------------------.pdf
Solve using Java programming language- ----------------------------.pdf
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
 

More from anjanacottonmills

Step1 First compound has 2 double bonds ; Second .pdf
                     Step1 First compound has 2 double bonds ; Second .pdf                     Step1 First compound has 2 double bonds ; Second .pdf
Step1 First compound has 2 double bonds ; Second .pdfanjanacottonmills
 
Molarity = molesvolume9liter) Molarity of NH4Cl.pdf
                     Molarity = molesvolume9liter)  Molarity of NH4Cl.pdf                     Molarity = molesvolume9liter)  Molarity of NH4Cl.pdf
Molarity = molesvolume9liter) Molarity of NH4Cl.pdfanjanacottonmills
 
HOCH2CH2OH is more soluble in water. more OH grou.pdf
                     HOCH2CH2OH is more soluble in water. more OH grou.pdf                     HOCH2CH2OH is more soluble in water. more OH grou.pdf
HOCH2CH2OH is more soluble in water. more OH grou.pdfanjanacottonmills
 
z=(2n+1)4where n=all integersSolutionz=(2n+1)4where n=al.pdf
z=(2n+1)4where n=all integersSolutionz=(2n+1)4where n=al.pdfz=(2n+1)4where n=all integersSolutionz=(2n+1)4where n=al.pdf
z=(2n+1)4where n=all integersSolutionz=(2n+1)4where n=al.pdfanjanacottonmills
 
This above plant name is Solidago sempervirens, belong to genus Soli.pdf
This above plant name is Solidago sempervirens, belong to genus Soli.pdfThis above plant name is Solidago sempervirens, belong to genus Soli.pdf
This above plant name is Solidago sempervirens, belong to genus Soli.pdfanjanacottonmills
 
The Java Program for the above given isimport java.io.File;impo.pdf
The Java Program for the above given isimport java.io.File;impo.pdfThe Java Program for the above given isimport java.io.File;impo.pdf
The Java Program for the above given isimport java.io.File;impo.pdfanjanacottonmills
 
The fidelity of DNA replication determines the genome stability and .pdf
The fidelity of DNA replication determines the genome stability and .pdfThe fidelity of DNA replication determines the genome stability and .pdf
The fidelity of DNA replication determines the genome stability and .pdfanjanacottonmills
 
E= 0.28V reactants are favored .pdf
                     E= 0.28V reactants are favored                   .pdf                     E= 0.28V reactants are favored                   .pdf
E= 0.28V reactants are favored .pdfanjanacottonmills
 
The differences between ipv4 and ipv6 are as below1. Header1.Ch.pdf
The differences between ipv4 and ipv6 are as below1. Header1.Ch.pdfThe differences between ipv4 and ipv6 are as below1. Header1.Ch.pdf
The differences between ipv4 and ipv6 are as below1. Header1.Ch.pdfanjanacottonmills
 
TCP - TCP breaks data into manageable packets and tracks information.pdf
TCP - TCP breaks data into manageable packets and tracks information.pdfTCP - TCP breaks data into manageable packets and tracks information.pdf
TCP - TCP breaks data into manageable packets and tracks information.pdfanjanacottonmills
 
Static arrays are structures whose size is fixed at compile time and.pdf
Static arrays are structures whose size is fixed at compile time and.pdfStatic arrays are structures whose size is fixed at compile time and.pdf
Static arrays are structures whose size is fixed at compile time and.pdfanjanacottonmills
 
D) II, III, IV, and V only .pdf
                     D) II, III, IV, and V only                       .pdf                     D) II, III, IV, and V only                       .pdf
D) II, III, IV, and V only .pdfanjanacottonmills
 
c) H2(g) + 12 O2(g) -H2O (l) as all are in the.pdf
                     c) H2(g) + 12 O2(g) -H2O (l)  as all are in the.pdf                     c) H2(g) + 12 O2(g) -H2O (l)  as all are in the.pdf
c) H2(g) + 12 O2(g) -H2O (l) as all are in the.pdfanjanacottonmills
 
MagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdfMagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdfanjanacottonmills
 
Interphase.This is the phase where the cell prepares for the next .pdf
Interphase.This is the phase where the cell prepares for the next .pdfInterphase.This is the phase where the cell prepares for the next .pdf
Interphase.This is the phase where the cell prepares for the next .pdfanjanacottonmills
 
B.the rotation will be zero as L and D will cance.pdf
                     B.the rotation will be zero as L and D will cance.pdf                     B.the rotation will be zero as L and D will cance.pdf
B.the rotation will be zero as L and D will cance.pdfanjanacottonmills
 
In the above conversation it is belonging to stereotypes.Stereotyp.pdf
In the above conversation it is belonging to stereotypes.Stereotyp.pdfIn the above conversation it is belonging to stereotypes.Stereotyp.pdf
In the above conversation it is belonging to stereotypes.Stereotyp.pdfanjanacottonmills
 
In general, the objective of an audit is to assess the risk of mater.pdf
In general, the objective of an audit is to assess the risk of mater.pdfIn general, the objective of an audit is to assess the risk of mater.pdf
In general, the objective of an audit is to assess the risk of mater.pdfanjanacottonmills
 
if one can understand a few things it is easier to solve these kind .pdf
if one can understand a few things it is easier to solve these kind .pdfif one can understand a few things it is easier to solve these kind .pdf
if one can understand a few things it is easier to solve these kind .pdfanjanacottonmills
 

More from anjanacottonmills (20)

Step1 First compound has 2 double bonds ; Second .pdf
                     Step1 First compound has 2 double bonds ; Second .pdf                     Step1 First compound has 2 double bonds ; Second .pdf
Step1 First compound has 2 double bonds ; Second .pdf
 
Molarity = molesvolume9liter) Molarity of NH4Cl.pdf
                     Molarity = molesvolume9liter)  Molarity of NH4Cl.pdf                     Molarity = molesvolume9liter)  Molarity of NH4Cl.pdf
Molarity = molesvolume9liter) Molarity of NH4Cl.pdf
 
HOCH2CH2OH is more soluble in water. more OH grou.pdf
                     HOCH2CH2OH is more soluble in water. more OH grou.pdf                     HOCH2CH2OH is more soluble in water. more OH grou.pdf
HOCH2CH2OH is more soluble in water. more OH grou.pdf
 
x = -2Solutionx = -2.pdf
x = -2Solutionx = -2.pdfx = -2Solutionx = -2.pdf
x = -2Solutionx = -2.pdf
 
z=(2n+1)4where n=all integersSolutionz=(2n+1)4where n=al.pdf
z=(2n+1)4where n=all integersSolutionz=(2n+1)4where n=al.pdfz=(2n+1)4where n=all integersSolutionz=(2n+1)4where n=al.pdf
z=(2n+1)4where n=all integersSolutionz=(2n+1)4where n=al.pdf
 
This above plant name is Solidago sempervirens, belong to genus Soli.pdf
This above plant name is Solidago sempervirens, belong to genus Soli.pdfThis above plant name is Solidago sempervirens, belong to genus Soli.pdf
This above plant name is Solidago sempervirens, belong to genus Soli.pdf
 
The Java Program for the above given isimport java.io.File;impo.pdf
The Java Program for the above given isimport java.io.File;impo.pdfThe Java Program for the above given isimport java.io.File;impo.pdf
The Java Program for the above given isimport java.io.File;impo.pdf
 
The fidelity of DNA replication determines the genome stability and .pdf
The fidelity of DNA replication determines the genome stability and .pdfThe fidelity of DNA replication determines the genome stability and .pdf
The fidelity of DNA replication determines the genome stability and .pdf
 
E= 0.28V reactants are favored .pdf
                     E= 0.28V reactants are favored                   .pdf                     E= 0.28V reactants are favored                   .pdf
E= 0.28V reactants are favored .pdf
 
The differences between ipv4 and ipv6 are as below1. Header1.Ch.pdf
The differences between ipv4 and ipv6 are as below1. Header1.Ch.pdfThe differences between ipv4 and ipv6 are as below1. Header1.Ch.pdf
The differences between ipv4 and ipv6 are as below1. Header1.Ch.pdf
 
TCP - TCP breaks data into manageable packets and tracks information.pdf
TCP - TCP breaks data into manageable packets and tracks information.pdfTCP - TCP breaks data into manageable packets and tracks information.pdf
TCP - TCP breaks data into manageable packets and tracks information.pdf
 
Static arrays are structures whose size is fixed at compile time and.pdf
Static arrays are structures whose size is fixed at compile time and.pdfStatic arrays are structures whose size is fixed at compile time and.pdf
Static arrays are structures whose size is fixed at compile time and.pdf
 
D) II, III, IV, and V only .pdf
                     D) II, III, IV, and V only                       .pdf                     D) II, III, IV, and V only                       .pdf
D) II, III, IV, and V only .pdf
 
c) H2(g) + 12 O2(g) -H2O (l) as all are in the.pdf
                     c) H2(g) + 12 O2(g) -H2O (l)  as all are in the.pdf                     c) H2(g) + 12 O2(g) -H2O (l)  as all are in the.pdf
c) H2(g) + 12 O2(g) -H2O (l) as all are in the.pdf
 
MagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdfMagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdf
 
Interphase.This is the phase where the cell prepares for the next .pdf
Interphase.This is the phase where the cell prepares for the next .pdfInterphase.This is the phase where the cell prepares for the next .pdf
Interphase.This is the phase where the cell prepares for the next .pdf
 
B.the rotation will be zero as L and D will cance.pdf
                     B.the rotation will be zero as L and D will cance.pdf                     B.the rotation will be zero as L and D will cance.pdf
B.the rotation will be zero as L and D will cance.pdf
 
In the above conversation it is belonging to stereotypes.Stereotyp.pdf
In the above conversation it is belonging to stereotypes.Stereotyp.pdfIn the above conversation it is belonging to stereotypes.Stereotyp.pdf
In the above conversation it is belonging to stereotypes.Stereotyp.pdf
 
In general, the objective of an audit is to assess the risk of mater.pdf
In general, the objective of an audit is to assess the risk of mater.pdfIn general, the objective of an audit is to assess the risk of mater.pdf
In general, the objective of an audit is to assess the risk of mater.pdf
 
if one can understand a few things it is easier to solve these kind .pdf
if one can understand a few things it is easier to solve these kind .pdfif one can understand a few things it is easier to solve these kind .pdf
if one can understand a few things it is easier to solve these kind .pdf
 

Recently uploaded

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 

Recently uploaded (20)

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 

NumberList.java (implements the linked list)public class NumberLis.pdf

  • 1. NumberList.java (implements the linked list) public class NumberList{ Node first; Node last; public NumberList(){ first = null; last = null; } public NumberList(Node node){ this.first = node; this.last = node; } public boolean isEmpty(){ return first == null; } public void setLast(Node node){ this.last = node; } public void insert(Node node){ if (first==null){ this.first = node; this.last = node; } else{ node.previous = this.last; node.previous.next = node; node.next = null; this.last = node; } } public boolean inList(String num){ Node l = first; while (l.next != null){ if (l.number.equals(num)){ return true;
  • 2. } else{ l = l.next; } } return false; } public void printList(){ Node l = first; while(l.next!=null){ System.out.print(l.number+" "); l = l.next; } System.out.println(); } } Node.java (implements a single node in the linked list; stores number and pointers) public class Node{ String number; Node previous; Node next; public Node(String num){ number = num; previous = null; next = null; } public Node(String num, Node p, Node n){ number = num; previous = p; next = n; } } Main.java (contains the main method and the helper methods to solve the questions given) import java.util.Scanner; import java.util.List;
  • 3. import java.util.ArrayList; public class Main{ static boolean checkHappiness(String num){ Node current = new Node(num, null, null); NumberList numberList = new NumberList(current); int len = num.length(); int resultant = 0; for (int i=0; i happyNumbersfrom1to10000(){ ArrayList numbers = new ArrayList(); for (int j=0; j<10000; j++){ if (checkHappiness(String.valueOf(j+1))){ numbers.add(String.valueOf(j+1)); } } return numbers; } static void happyNumbersfrom9001to10000(){ for (int j=9001; j<=10000; j++){ //System.out.println(j); if (checkHappiness(String.valueOf(j))){ System.out.println(String.valueOf(j)); } } } static String getLargeHappyNumber(){ for (long i=10000000000000000000L; i<1000000000000000000000L; i++){ if (checkHappiness(String.valueOf(i))){ return String.valueOf(i); } return "-1"; } } static String getLargeUnhappyNumber(){ for (long i=10000000000000000000L; i<1000000000000000000000L; i++){ if (!checkHappiness(String.valueOf(i))){ return String.valueOf(i);
  • 4. } return "-1"; } } public static void main(String[] args){ happyNumbersfrom9001to10000(); System.out.println(happyNumbersfrom1to10000()); } } Solution NumberList.java (implements the linked list) public class NumberList{ Node first; Node last; public NumberList(){ first = null; last = null; } public NumberList(Node node){ this.first = node; this.last = node; } public boolean isEmpty(){ return first == null; } public void setLast(Node node){ this.last = node; } public void insert(Node node){ if (first==null){ this.first = node; this.last = node; }
  • 5. else{ node.previous = this.last; node.previous.next = node; node.next = null; this.last = node; } } public boolean inList(String num){ Node l = first; while (l.next != null){ if (l.number.equals(num)){ return true; } else{ l = l.next; } } return false; } public void printList(){ Node l = first; while(l.next!=null){ System.out.print(l.number+" "); l = l.next; } System.out.println(); } } Node.java (implements a single node in the linked list; stores number and pointers) public class Node{ String number; Node previous; Node next; public Node(String num){ number = num; previous = null;
  • 6. next = null; } public Node(String num, Node p, Node n){ number = num; previous = p; next = n; } } Main.java (contains the main method and the helper methods to solve the questions given) import java.util.Scanner; import java.util.List; import java.util.ArrayList; public class Main{ static boolean checkHappiness(String num){ Node current = new Node(num, null, null); NumberList numberList = new NumberList(current); int len = num.length(); int resultant = 0; for (int i=0; i happyNumbersfrom1to10000(){ ArrayList numbers = new ArrayList(); for (int j=0; j<10000; j++){ if (checkHappiness(String.valueOf(j+1))){ numbers.add(String.valueOf(j+1)); } } return numbers; } static void happyNumbersfrom9001to10000(){ for (int j=9001; j<=10000; j++){ //System.out.println(j); if (checkHappiness(String.valueOf(j))){ System.out.println(String.valueOf(j)); } } }
  • 7. static String getLargeHappyNumber(){ for (long i=10000000000000000000L; i<1000000000000000000000L; i++){ if (checkHappiness(String.valueOf(i))){ return String.valueOf(i); } return "-1"; } } static String getLargeUnhappyNumber(){ for (long i=10000000000000000000L; i<1000000000000000000000L; i++){ if (!checkHappiness(String.valueOf(i))){ return String.valueOf(i); } return "-1"; } } public static void main(String[] args){ happyNumbersfrom9001to10000(); System.out.println(happyNumbersfrom1to10000()); } }