What's new

Java Pa help po Data Structure

EpicPrivacy

Eternal Poster
Joined
May 16, 2016
Posts
1,173
Reaction
381
Points
421
Code:
do{
        System.out.println("Note: You can enter Small and Big Letter");
        System.out.println("Choices: ");
        System.out.println("\t[I] – Insert");
        System.out.println("\t[D] – Delete");
        System.out.println("\t[S] – Search");
        System.out.println("\t[P] – Print");
        System.out.println("\t[C] - Close");
       
        System.out.print("Enter you choise: ");
        choise = scan.next().charAt(0);
       
        // Enter
            if(choise == 'I' || choise == 'i'){
                System.out.print("Enter an integer: ");
                enter = scan1.nextInt();
                List.Add(enter);
                System.out.print("\n");
            }
        // Delete
            if(choise == 'D' || choise == 'd'){
                List.Delete();
           for (Node q = head; q !=null; q = q.next)
        System.out.println("The integers are: " + q.data);
                System.out.print("\n");
            }
        // Search
            if(choise == 'S' || choise == 's'){
             
        System.out.print("Enter the number to be searched: ");
                search = scan1.nextInt();
                for (Node q = head; q !=null; q = q.next)
                if(search != q.data){
                System.out.print(search + " is not in the list");
                System.out.print("\n\n");
                }else{
                System.out.print(search + " is in the list");
                System.out.print("\n\n");
                }
                System.out.print("\n\n");
               
            }
        // Printing
            if(choise == 'P' || choise == 'p'){
                for (Node q = head; q !=null; q = q.next)
                System.out.println("The integers are: " + q.data);
                System.out.print("\n");
            }
        // Close
        }while(choise != 'C' && choise != 'c');

         System.out.print("Closing the program. Thank you!\n");
         System.exit(0);


pano po kaya ma fix to:

Note: You can enter Small and Big Letter
Choices:
– Insert
[D] – Delete
– Search
[P] – Print
[C] - Close
Enter you choise: i
Enter an integer: 10

Note: You can enter Small and Big Letter
Choices:
– Insert
[D] – Delete
– Search
[P] – Print
[C] - Close
Enter you choise: i
Enter an integer: 100

Note: You can enter Small and Big Letter
Choices:
– Insert
[D] – Delete
– Search
[P] – Print
[C] - Close
Enter you choise: i
Enter an integer: 200

Note: You can enter Small and Big Letter
Choices:
– Insert
[D] – Delete
– Search
[P] – Print
[C] - Close
Enter you choise: s
Enter the number to be searched: 90
90 is not in the list

90 is not in the list

90 is not in the list



Note: You can enter Small and Big Letter
Choices:
– Insert
[D] – Delete
– Search
[P] – Print
[C] - Close
Enter you choise: p
The integers are: 200
The integers are: 100
The integers are: 10



nag dodoble doble po kasi yung pag print nya ng 90 is not in the list
at dun sa the integers are pano po kaya pag sunod sunudin yung output nya sample The integers are: 10 100 200
 
Last edited:
Yung sa bandang search mo po ay hindi naka enclosed sa loop (curly braces) yung mga conditional statements mo.
Para hindi mag multiple print try mo po,
Java:
if(search == q.data)
//Then print search is in the list.
 

Similar threads

Back
Top