From e6a751223db5650efd790270f6b0fddbf5d57830 Mon Sep 17 00:00:00 2001 From: Iquer_Dough <206500499+DennysSaenz123@users.noreply.github.com> Date: Mon, 12 May 2025 11:48:52 -0700 Subject: [PATCH] Followed livecode --- src/ListNode.java | 7 ++++++- src/Practice.java | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/ListNode.java b/src/ListNode.java index dd6028c..4748bf9 100644 --- a/src/ListNode.java +++ b/src/ListNode.java @@ -1,3 +1,8 @@ public class ListNode { - + public int data; + public ListNode next; + + public ListNode(int data){ + this.data = data; + } } \ No newline at end of file diff --git a/src/Practice.java b/src/Practice.java index 34a2f8d..46ec55f 100644 --- a/src/Practice.java +++ b/src/Practice.java @@ -1,5 +1,28 @@ + public class Practice { public static void main(String[] args) { + ListNode head = new ListNode(14); + ListNode mySeven = new ListNode(7); + + head.next = mySeven; + + mySeven.next = new ListNode(28); + head.next.next.next = new ListNode(32); + head.next.next.next.next = new ListNode(23); + // System.out.println(head); + + ListNode current = head; + int total = 0; + + while(current != null){ + // System.out.println(current.data); + total += current.data; + current = current.next; + if(current == null){ + System.out.println("bih"); + } + } + System.out.println(total); } }