Description
The main objective of this lab is to create a data analyzer with four functions such as; asking user to input different numbers and then, order it in ascending mode, then, in they way they were entered, and finally displaying all the numbers once. Therefore, the program has two menus one asking of what kind of data is the user about to input whether it’s double, integer or string and then a second following menu asking how many integers does the user wants to analyze..
Code
//Lab 8 By Tax, Julio import java.util.LinkedList; import java.util.Scanner; import java.util.Stack; import java.util.TreeSet; import java.util.List; import java.util.Collections; public class DataStructure { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in); Stack s = new Stack(); LinkedList r = new LinkedList(); LinkedList r2 = new LinkedList(); TreeSet d = new TreeSet(); int b = 0; int f = 0; System.out.print("How many Numbers would you like to enter?"); f = input.nextInt(); while(b < f) { System.out.print("Please Enter those Numbers"); Integer num = input.nextInt(); r.addFirst(num); s.push(num); d.add(num); b++; } r2.addAll(r); Collections.sort(r2); System.out.printf("numbers in reversed Order:%s\n",r); System.out.printf("numbers in the order they were entered:%s\n",s); System.out.printf("numbers in ascending order:%s\n",r2); System.out.printf("number entered:%s\n",d); } }
Screenshots