diagnonsense's Profile
Reputation: 0
Apprentice
- Group:
- Members
- Active Posts:
- 37 (0.08 per day)
- Joined:
- 11-February 12
- Profile Views:
- 221
- Last Active:
Mar 05 2013 07:52 PM- Currently:
- Offline
Previous Fields
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: Can someone explain running times (constant, linear, nlogn) and Heaps?
Posted 2 Mar 2013
Alright thanks for your explanation, I think I understand that a heap construction should take theta(1) time. This would be constant I assume. How would I make a constructor that is linear and nlogn then? That's the part that is throwing me off. -
In Topic: Spelling numbers using Queues
Posted 25 Feb 2013
Ok so I actually figured how to do this but only for numbers that are 3 digits long. I can't figure out how to accurately implement the "thousands, millions, billions" part of the code. I know it has something to do with the size divided by three.
For example: 123456 has a size of 6 so 6/3 is 2 and that would mean 2 = thousand. But, I don't know where to put that in my code
import java.util.*;//needed for Stack class public class ReadNumsWithQueue2 { private static String startNumber;//creates variable to hold the initial integer private Queue<Integer> masterQueue = new LinkedList<Integer>();//creates the stack to hold the list of integers private Queue<String> masterAnswer = new LinkedList<String>();//creates String variable for the final answer private int bigNumber = -1;//to hold which position in the largeNames array we are at private String masterStringAnswer = ""; //creates arrays to hold the word equivilents of the numbers //assigns array the names of the basic numbers String[] basicNames = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; //assigns array the names of the teen numbers String[] teenNames = {"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"}; //assigns array the names of the -ty numbers String[] tyNames = {"twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninty"}; //assigns array the names of all the different large numbers String[] largeNames = {"thousand", "million", "billion", "trillion", "quadrillion", "quintillion", "sextillion", "septillion", "octillion", "nonillion", "decillion", "undecillion", "duodecillion", "tredecillion", "quattuordecillion", "quindecillion"}; //constructor public ReadNumsWithQueue2 (String userInput) { super();//calls the constructor of the superclass startNumber = userInput;//tranfers the data into a private variable }//end method //method to convert the user input into usable data public void parseStartNumber () { String lastChar;//will hold the character to be parsed while ((!startNumber.equals("")) && (startNumber != null)) { lastChar = startNumber.substring(0, 1);//gets first char startNumber = startNumber.substring(1);//deletes the first char from the String //converts string to integer int tempInt = Integer.parseInt(lastChar); masterQueue.add(tempInt);//adds digit to queue }//end while System.out.println(masterQueue); }//end method //converts the number to word format public void convertToString () { int size = masterQueue.size(); int mod = size%3; int place = size/3; //System.out.println(numOne); if(mod != 0){ //begins with two digits int numOne = masterQueue.remove(); if (mod == 2){ //two digits if(!masterQueue.isEmpty()){//not empty after removing numOne int numTwo = masterQueue.remove(); //remove second number //System.out.println(numTwo); if(numOne == 1){ masterAnswer.add(" " + teenNames[numTwo]); } else{ if(numTwo != 0){ if (numOne != 0){ masterAnswer.add("-" + basicNames[(numTwo - 1)]); } masterAnswer.add(" " + tyNames[(numOne - 2)]); } else if (numTwo == 0 && numOne != 0)//if the tens digit is 0 but the 'ones' is not masterAnswer.add(" " + basicNames[(numOne - 1)]); } } } else //one digit masterAnswer.add(" " + basicNames[(numOne - 1)]); } else if(mod == 0){//beginning of the number starts with 3 digits int numOne = masterQueue.remove(); int numTwo = masterQueue.remove(); //remove second number int numThree = masterQueue.remove(); //remove third number System.out.println(numOne); System.out.println(numTwo); System.out.println(numThree); if(numOne != 0){ masterAnswer.add(" " + basicNames[numOne - 1] + " hundred"); } if(numTwo != 0 && numThree != 0){ if(numTwo != 0){ masterAnswer.add(" " + tyNames[(numTwo - 2)]); if (numThree != 0){ masterAnswer.add("-" + basicNames[(numThree - 1)]); } } else if (numTwo == 0 && numThree != 0)//if the tens digit is 0 but the 'ones' is not masterAnswer.add(" " + basicNames[(numOne - 1)]); } } } //simply takes all the String objects that are in the secondary stack, //and inputs them into one single string variable public void stackToString () { while (!masterAnswer.isEmpty()) { masterStringAnswer += masterAnswer.remove(); } } //extra method that edits the final string to look a little more presentable //it removes the leading space, and capitalizes the first letter public void fixInitialChar () { String letterToFix = masterStringAnswer.substring(1, 2); letterToFix = letterToFix.toUpperCase(); masterStringAnswer = letterToFix + masterStringAnswer.substring(2); } //returns final answer public String getMasterAnswer() { return masterStringAnswer; } }//end class -
In Topic: Spelling numbers using Queues
Posted 22 Feb 2013
-
In Topic: Finding the term with maximum recursive calls
Posted 11 Feb 2013
Update: Also it seems like cnt is never being stored in fincnt, fincnt just stays zero through the entire for loop. Why is that?
I wrote the if statement to work if cnt is larger than fincnt, I don't see what's wrong. -
In Topic: Finding the term with maximum recursive calls
Posted 11 Feb 2013
Ok so I'm trying to make a for loop that goes through each GCD and records the count as well as the y value that count was found at.
Can someone tell me why this code is not working? It just produces a ton of 1's and it has something to do with the i = ansy; line.
All I'm trying to do is store the i value which is equal to the y value in a variable called ansy
import java.util.Scanner; /** This program demonstrates the recursive gcd method. */ public class GCDdemo { static int cnt = 0; static int ansy = 0; static int fincnt = 0; public static void main(String[] args) { for(int i=1;i<988;i++){ gcd(987,i); System.out.println(cnt); if (cnt > fincnt){ cnt = fincnt; i = ansy; } cnt = 0; } System.out.println(fincnt); System.out.println(ansy); } public static int gcd(int x, int y) { cnt++; if (x % y == 0) return y; else return gcd(y, x % y); } }
My Information
- Member Title:
- New D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
Contact Information
- E-mail:
- Private
Friends
diagnonsense hasn't added any friends yet.
|
|


Find Topics
Find Posts
View Reputation Given

|
Comments
diagnonsense has no profile comments yet. Why not say hello?