Search Results

Search found 73 results on 3 pages for 'user69514'.

Page 1/3 | 1 2 3  | Next Page >

  • How to determine if binary tree is balanced?

    - by user69514
    It's been a while from those school years. Got a job as IT specialist at a hospital. Trying to move to do some actual programming now. I'm working on binary trees now, and I was wondering what would be the best way to determine if the tree is height-balanced. I was thinking of something along this: public boolean isBalanced(Node root){ if(root==null){ return true; //tree is empty } else{ int lh = root.left.height(); int rh = root.right.height(); if(lh - rh > 1 || rh - lh > 1){ return false; } } return true; } Is this a good implementation? or am I missing something?

    Read the article

  • C - check if string is a substring of another string

    - by user69514
    I need to write a program that takes two strings as arguments and check if the second one is a substring of the first one. I need to do it without using any special library functions. I created this implementation, but I think it's always returning true as long as there is one letter that's the same in both strings. Can you help me out here. I'm not sure what I am doing wrong: #include <stdio.h> #include <string.h> int my_strstr( char const *s, char const *sub ) { char const *ret = sub; int r = 0; while ( ret = strchr( ret, *sub ) ) { if ( strcmp( ++ret, sub+1 ) == 0 ){ r = 1; } else{ r = 0; } } return r; } int main(int argc, char **argv){ if (argc != 3) { printf ("Usage: check <string one> <string two>\n"); } int result = my_strstr(argv[1], argv[2]); if(result == 1){ printf("%s is a substring of %s\n", argv[2], argv[1]); } else{ printf("%s is not a substring of %s\n", argv[2], argv[1]); } return 0; }

    Read the article

  • Java Graphics2D DrawString....

    - by user69514
    Hey guys I have a little issue here. I have a panel where I am drawing a string. This is a game so I keep redrawing the score in order to update it. However when I draw it again it is drawn on top of the previous score so it looked all garbled up. Any ideas how to fix this? comp2d.drawString(GetScore(Score),ScoreX,ScoreY);

    Read the article

  • Java JPanel not showing up....

    - by user69514
    I'm not sure what I am doing wrong, but the text for my JPanels is not showing up. I just get the question number text, but the question is not showing up. Any ideas what I am doing wrong? import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; class NewFrame extends JFrame { JPanel centerpanel; // For the questions. CardLayout card; // For the centerpanel. JTextField tf; // Used in question 1. boolean // Store selections for Q2. q2Option1, q2Option2, q2Option3, q2Option4; JList q4List; // For question 4. double // Score on each question. q1Score = 0, q2Score = 0, q3Score = 0, q4Score = 0; // Constructor. public NewFrame (int width, int height) { this.setTitle ("Snoot Club Membership Test"); this.setResizable (true); this.setSize (width, height); Container cPane = this.getContentPane(); // cPane.setLayout (new BorderLayout()); // First, a welcome message, as a Label. JLabel L = new JLabel ("<html><b>Are you elitist enough for our exclusive club?" + " <br>Fill out the form and find out</b></html>"); L.setForeground (Color.blue); cPane.add (L, BorderLayout.NORTH); // Now the center panel with the questions. card = new CardLayout (); centerpanel = new JPanel (); centerpanel.setLayout (card); centerpanel.setOpaque (false); // Each question will be created in a separate method. // The cardlayout requires a label as second parameter. centerpanel.add (firstQuestion (), "1"); centerpanel.add (secondQuestion(), "2"); centerpanel.add (thirdQuestion(), "3"); centerpanel.add (fourthQuestion(), "4"); cPane.add (centerpanel, BorderLayout.CENTER); // Next, a panel of four buttons at the bottom. // The four buttons: quit, submit, next-question, previous-question. JPanel bottomPanel = getBottomPanel (); cPane.add (bottomPanel, BorderLayout.SOUTH); // Finally, show the frame. this.setVisible (true); } // No-parameter constructor. public NewFrame () { this (500, 300); } // The first question uses labels for the question and // gets input via a textfield. A panel containing all // these things is returned. The question asks for // a vacation destination: the more exotic the location, // the higher the score. JPanel firstQuestion () { // We will package everything into a panel and return the panel. JPanel subpanel = new JPanel (); // We will place things in a single column, so // a GridLayout with one column is appropriate. subpanel.setLayout (new GridLayout (8,1)); JLabel L1 = new JLabel ("Question 1:"); L1.setFont (new Font ("SansSerif", Font.ITALIC, 15)); subpanel.add (L1); JLabel L2 = new JLabel (" Select a vacation destination"); L2.setFont (new Font ("SansSerif", Font.ITALIC, 15)); subpanel.add (L2); JLabel L3 = new JLabel (" 1. Baltimore"); L3.setFont (new Font ("SansSerif", Font.ITALIC, 15)); subpanel.add (L3); JLabel L4 = new JLabel (" 2. Disneyland"); L4.setFont (new Font ("SansSerif", Font.ITALIC, 15)); subpanel.add (L4); JLabel L5 = new JLabel (" 3. Grand Canyon"); L5.setFont (new Font ("SansSerif", Font.ITALIC, 15)); subpanel.add (L5); JLabel L6 = new JLabel (" 4. French Riviera"); L6.setFont (new Font ("SansSerif", Font.ITALIC, 15)); subpanel.add (L6); JLabel L7 = new JLabel ("Enter 1,2,3 or 4 below:"); L7.setFont (new Font ("SansSerif", Font.ITALIC, 15)); subpanel.add (L7); // Here's the textfield to get user-input. tf = new JTextField (); tf.addActionListener ( new ActionListener () { // This interface has only one method. public void actionPerformed (ActionEvent a) { String q1String = a.getActionCommand(); if (q1String.equals ("2")) q1Score = 2; else if (q1String.equals ("3")) q1Score = 3; else if (q1String.equals ("4")) q1Score = 4; else q1Score = 1; } } ); subpanel.add (tf); return subpanel; } // For the second question, a collection of checkboxes // will be used. More than one selection can be made. // A listener is required for each checkbox. The state // of each checkbox is recorded. JPanel secondQuestion () { JPanel subpanel = new JPanel (); subpanel.setLayout (new GridLayout (7,1)); JLabel L1 = new JLabel ("Question 2:"); L1.setFont (new Font ("SansSerif", Font.ITALIC, 15)); subpanel.add (L1); JLabel L2 = new JLabel (" Select ONE OR MORE things that "); L2.setFont (new Font ("SansSerif", Font.ITALIC, 15)); subpanel.add (L2); JLabel L3 = new JLabel (" you put into your lunch sandwich"); L3.setFont (new Font ("SansSerif", Font.ITALIC, 15)); subpanel.add (L3); // Initialize the selections to false. q2Option1 = q2Option2 = q2Option3 = q2Option4 = false; // First checkbox. JCheckBox c1 = new JCheckBox ("Ham, beef or turkey"); c1.addItemListener ( new ItemListener () { public void itemStateChanged (ItemEvent i) { JCheckBox c = (JCheckBox) i.getSource(); q2Option1 = c.isSelected(); } } ); subpanel.add (c1); // Second checkbox. JCheckBox c2 = new JCheckBox ("Cheese"); c2.addItemListener ( new ItemListener () { // This is where we will react to a change in checkbox. public void itemStateChanged (ItemEvent i) { JCheckBox c = (JCheckBox) i.getSource(); q2Option2 = c.isSelected(); } } ); subpanel.add (c2); // Third checkbox. JCheckBox c3 = new JCheckBox ("Sun-dried Arugula leaves"); c3.addItemListener ( new ItemListener () { public void itemStateChanged (ItemEvent i) { JCheckBox c = (JCheckBox) i.getSource(); q2Option3 = c.isSelected(); } } ); subpanel.add (c3); // Fourth checkbox. JCheckBox c4 = new JCheckBox ("Lemon-enhanced smoked Siberian caviar"); c4.addItemListener ( new ItemListener () { public void itemStateChanged (ItemEvent i) { JCheckBox c = (JCheckBox) i.getSource(); q2Option4 = c.isSelected(); } } ); subpanel.add (c4); return subpanel; } // The third question allows only one among four choices // to be selected. We will use radio buttons. JPanel thirdQuestion () { JPanel subpanel = new JPanel (); subpanel.setLayout (new GridLayout (6,1)); JLabel L1 = new JLabel ("Question 3:"); L1.setFont (new Font ("SansSerif", Font.ITALIC, 15)); subpanel.add (L1); JLabel L2 = new JLabel (" And which mustard do you use?"); L2.setFont (new Font ("SansSerif", Font.ITALIC, 15)); subpanel.add (L2); // First, create the ButtonGroup instance. // We will add radio buttons to this group. ButtonGroup bGroup = new ButtonGroup(); // First checkbox. JRadioButton r1 = new JRadioButton ("Who cares?"); r1.addItemListener ( new ItemListener () { public void itemStateChanged (ItemEvent i) { JRadioButton r = (JRadioButton) i.getSource(); if (r.isSelected()) q3Score = 1; } } ); bGroup.add (r1); subpanel.add (r1); // Second checkbox. JRadioButton r2 = new JRadioButton ("Safeway Brand"); r2.addItemListener ( new ItemListener () { public void itemStateChanged (ItemEvent i) { JRadioButton r = (JRadioButton) i.getSource(); if (r.isSelected()) q3Score = 2; } } ); bGroup.add (r2); subpanel.add (r2); // Third checkbox. JRadioButton r3 = new JRadioButton ("Fleishman's"); r3.addItemListener ( new ItemListener () { public void itemStateChanged (ItemEvent i) { JRadioButton r = (JRadioButton) i.getSource(); if (r.isSelected()) q3Score = 3; } } ); bGroup.add (r3); subpanel.add (r3); // Fourth checkbox. JRadioButton r4 = new JRadioButton ("Grey Poupon"); r4.addItemListener ( new ItemListener () { public void itemStateChanged (ItemEvent i) { JRadioButton r = (JRadioButton) i.getSource(); if (r.isSelected()) q3Score = 4; } } ); bGroup.add (r4); subpanel.add (r4); return subpanel; } // For the fourth question we will use a drop-down Choice. JPanel fourthQuestion () { JPanel subpanel = new JPanel (); subpanel.setLayout (new GridLayout (3,1)); JLabel L1 = new JLabel ("Question 4:"); L1.setFont (new Font ("SansSerif", Font.ITALIC, 15)); subpanel.add (L1); JLabel L2 = new JLabel (" Your movie preference, among these:"); L2.setFont (new Font ("SansSerif", Font.ITALIC, 15)); subpanel.add (L2); // Create a JList with options. String[] movies = { "Lethal Weapon IV", "Titanic", "Saving Private Ryan", "Le Art Movie avec subtitles"}; q4List = new JList (movies); q4Score = 1; q4List.addListSelectionListener ( new ListSelectionListener () { public void valueChanged (ListSelectionEvent e) { q4Score = 1 + q4List.getSelectedIndex(); } } ); subpanel.add (q4List); return subpanel; } void computeResult () { // Clear the center panel. centerpanel.removeAll(); // Create a new panel to display in the center. JPanel subpanel = new JPanel (new GridLayout (5,1)); // Score on question 1. JLabel L1 = new JLabel ("Score on question 1: " + q1Score); L1.setFont (new Font ("Serif", Font.ITALIC, 15)); subpanel.add (L1); // Score on question 2. if (q2Option1) q2Score += 1; if (q2Option2) q2Score += 2; if (q2Option3) q2Score += 3; if (q2Option4) q2Score += 4; q2Score = 0.6 * q2Score; JLabel L2 = new JLabel ("Score on question 2: " + q2Score); L2.setFont (new Font ("Serif", Font.ITALIC, 15)); subpanel.add (L2); // Score on question 3. JLabel L3 = new JLabel ("Score on question 3: " + q3Score); L3.setFont (new Font ("Serif", Font.ITALIC, 15)); subpanel.add (L3); // Score on question 4. JLabel L4 = new JLabel ("Score on question 4: " + q4Score); L4.setFont (new Font ("Serif", Font.ITALIC, 15)); subpanel.add (L4); // Weighted score. double avg = (q1Score + q2Score + q3Score + q4Score) / (double) 4; JLabel L5; if (avg <= 3.5) L5 = new JLabel ("Your average score: " + avg + " - REJECTED!"); else L5 = new JLabel ("Your average score: " + avg + " - WELCOME!"); L5.setFont (new Font ("Serif", Font.BOLD, 20)); //L5.setAlignment (JLabel.CENTER); subpanel.add (L5); // Now add the new subpanel. centerpanel.add (subpanel, "5"); // Need to mark the centerpanel as "altered" centerpanel.invalidate(); // Everything "invalid" (e.g., the centerpanel above) // is now re-computed. this.validate(); } JPanel getBottomPanel () { // Create a panel into which we will place buttons. JPanel bottomPanel = new JPanel (); // A "previous-question" button. JButton backward = new JButton ("Previous question"); backward.setFont (new Font ("Serif", Font.PLAIN | Font.BOLD, 15)); backward.addActionListener ( new ActionListener () { public void actionPerformed (ActionEvent a) { // Go back in the card layout. card.previous (centerpanel); } } ); bottomPanel.add (backward); // A forward button. JButton forward = new JButton ("Next question"); forward.setFont (new Font ("Serif", Font.PLAIN | Font.BOLD, 15)); forward.addActionListener ( new ActionListener () { public void actionPerformed (ActionEvent a) { // Go forward in the card layout. card.next (centerpanel); } } ); bottomPanel.add (forward); // A submit button. JButton submit = new JButton ("Submit"); submit.setFont (new Font ("Serif", Font.PLAIN | Font.BOLD, 15)); submit.addActionListener ( new ActionListener () { public void actionPerformed (ActionEvent a) { // Perform submit task. computeResult(); } } ); bottomPanel.add (submit); JButton quitb = new JButton ("Quit"); quitb.setFont (new Font ("Serif", Font.PLAIN | Font.BOLD, 15)); quitb.addActionListener ( new ActionListener () { public void actionPerformed (ActionEvent a) { System.exit (0); } } ); bottomPanel.add (quitb); return bottomPanel; } } public class Survey { public static void main (String[] argv) { NewFrame nf = new NewFrame (600, 300); } }

    Read the article

  • User input... How to check for ENTER key

    - by user69514
    I have a section of code where the user enters input from the keyboard. I want to do something when ENTER is pressed. I am checking for '\n' but it's not working. How do you check if the user pressed the ENTER key? if( shuffle == false ){ int i=0; string line; while( i<20){ cout << "Playing: "; songs[i]->printSong(); cout << "Press ENTER to stop or play next song: "; getline(cin, line); if( line.compare("\n") == 0 ){ i++; } } }

    Read the article

  • Rotate two dimensional array 90 degrees clockwise

    - by user69514
    I have a two dimensional array that I need to rotate 90 degrees clockwise, however I keep getting arrayindexoutofbounds... public int[][] rorateArray(int[][] arr){ //first change the dimensions vertical length for horizontal length //and viceversa int[][] newArray = new int[arr[0].length][arr.length]; //invert values 90 degrees clockwise by starting from button of //array to top and from left to right int ii = 0; int jj = 0; for(int i=0; i<arr[0].length; i++){ for(int j=arr.length-1; j>=0; j--){ newArray[ii][jj] = arr[i][j]; jj++; } ii++; } return newArray; }

    Read the article

  • Check if a String is a double or an int?

    - by user69514
    I have a string for a Date in the form mm/dd, and I need to check if either the month or day was entered as a double public Date(String dateStr){ int slash = 0; //check slash is present try{ slash = dateStr.indexOf('/'); }catch(StringIndexOutOfBoundsException e){ error = "Invalid date format: " + dateStr; } //check if month is a number try{ month = Integer.parseInt(dateStr.substring(0, slash)); //day = Integer.parseInt(dateStr.substring(slash + 1, dateStr.length())); } catch(NumberFormatException e){ System.out.println("Invalid format for input string: " + dateStr.substring(0, slash)); } //check if day is a number try{ day = Integer.parseInt(dateStr.substring(slash + 1, dateStr.length())); } catch(NumberFormatException e){ System.out.println("Invalid format for input string: " + dateStr.substring(slash + 1, dateStr.length())); } //check if month was entered as a double }

    Read the article

  • Java FileInputStream ObjectInputStream reaches end of file EOF

    - by user69514
    I am trying to read the number of line in a binary file using readObject, but I get IOException EOF. Am I doing this the right way? FileInputStream istream = new FileInputStream(fileName); ObjectInputStream ois = new ObjectInputStream(istream); /** calculate number of items **/ int line_count = 0; while( (String)ois.readObject() != null){ line_count++; }

    Read the article

  • C++ alignment when printing cout <<

    - by user69514
    Is there a way to align text when priting using cout? I'm using tabs, but when the words are too big they won't be aligned anymore Sales Report for September 15, 2010 Artist Title Price Genre Disc Sale Tax Cash Merle Blue 12.99 Country 4% 12.47 1.01 13.48 Richard Music 8.49 Classical 8% 7.81 0.66 8.47 Paula Shut 8.49 Classical 8% 7.81 0.72 8.49

    Read the article

  • Java implementing Exception Handling

    - by user69514
    I am trying to implement an OutOfStockException for when the user attempts to buy more items than there are available. I'm not sure if my implementation is correct. Does this look OK to you? public class OutOfStockException extends Exception { public OutOfStockException(){ super(); } public OutOfStockException(String s){ super(s); } } This is the class where I need to test it: import javax.swing.JOptionPane; public class SwimItems { static final int MAX = 100; public static void main (String [] args) { Item [] items = new Item[MAX]; int numItems; numItems = fillFreebies(items); numItems += fillTaxable(items,numItems); numItems += fillNonTaxable(items,numItems); sellStuff(items, numItems); } private static int num(String which) { int n = 0; do { try{ n=Integer.parseInt(JOptionPane.showInputDialog("Enter number of "+which+" items to add to stock:")); } catch(NumberFormatException nfe){ System.out.println("Number Format Exception in num method"); } } while (n < 1 || n > MAX/3); return n; } private static int fillFreebies(Item [] list) { int n = num("FREEBIES"); for (int i = 0; i < n; i++) try{ list [i] = new Item(JOptionPane.showInputDialog("What freebie item will you give away?"), Integer.parseInt(JOptionPane.showInputDialog("How many do you have?"))); } catch(NumberFormatException nfe){ System.out.println("Number Format Exception in fillFreebies method"); } catch(ArrayIndexOutOfBoundsException e){ System.out.println("Array Index Out Of Bounds Exception in fillFreebies method"); } return n; } private static int fillTaxable(Item [] list, int number) { int n = num("Taxable Items"); for (int i = number ; i < n + number; i++) try{ list [i] = new TaxableItem(JOptionPane.showInputDialog("What taxable item will you sell?"), Double.parseDouble(JOptionPane.showInputDialog("How much will you charge (not including tax) for each?")), Integer.parseInt(JOptionPane.showInputDialog("How many do you have?"))); } catch(NumberFormatException nfe){ System.out.println("Number Format Exception in fillTaxable method"); } catch(ArrayIndexOutOfBoundsException e){ System.out.println("Array Index Out Of Bounds Exception in fillTaxable method"); } return n; } private static int fillNonTaxable(Item [] list, int number) { int n = num("Non-Taxable Items"); for (int i = number ; i < n + number; i++) try{ list [i] = new SaleItem(JOptionPane.showInputDialog("What non-taxable item will you sell?"), Double.parseDouble(JOptionPane.showInputDialog("How much will you charge for each?")), Integer.parseInt(JOptionPane.showInputDialog("How many do you have?"))); } catch(NumberFormatException nfe){ System.out.println("Number Format Exception in fillNonTaxable method"); } catch(ArrayIndexOutOfBoundsException e){ System.out.println("Array Index Out Of Bounds Exception in fillNonTaxable method"); } return n; } private static String listEm(Item [] all, int n, boolean numInc) { String list = "Items: "; for (int i = 0; i < n; i++) { try{ list += "\n"+ (i+1)+". "+all[i].toString() ; if (all[i] instanceof SaleItem) list += " (taxable) "; if (numInc) list += " (Number in Stock: "+all[i].getNum()+")"; } catch(ArrayIndexOutOfBoundsException e){ System.out.println("Array Index Out Of Bounds Exception in listEm method"); } catch(NullPointerException npe){ System.out.println("Null Pointer Exception in listEm method"); } } return list; } private static void sellStuff (Item [] list, int n) { int choice; do { try{ choice = Integer.parseInt(JOptionPane.showInputDialog("Enter item of choice: "+listEm(list, n, false))); } catch(NumberFormatException nfe){ System.out.println("Number Format Exception in sellStuff method"); } }while (JOptionPane.showConfirmDialog(null, "Another customer?")==JOptionPane.YES_OPTION); JOptionPane.showMessageDialog(null, "Remaining "+listEm(list, n, true)); } }

    Read the article

  • Java, LinkedList of Strings. Insert in alphabetical order

    - by user69514
    I have a simple linked list. The node contains a string (value) and an int (count). In the linkedlist when I insert I need to insert the new Node in alphabetical order. If there is a node with the same value in the list, then I simply increment the count of the node. I think I got my method really screwed up. public void addToList(Node node){ //check if list is empty, if so insert at head if(count == 0 ){ head = node; head.setNext(null); count++; } else{ Node temp = head; for(int i=0; i<count; i++){ //if value is greater, insert after if(node.getItem().getValue().compareTo(temp.getItem().getValue()) > 0){ node.setNext(temp.getNext()); temp.setNext(node); } //if value is equal just increment the counter else if(node.getItem().getValue().compareTo(temp.getItem().getValue()) == 0){ temp.getItem().setCount(temp.getItem().getCount() + 1); } //else insert before else{ node.setNext(temp); } } } }

    Read the article

  • java recursion on array

    - by user69514
    I have to create a program that finds all the possible ways of filling a board of size 3xN You place a domino which takes up 2 spaces to completely fill the board. So far, this is my thought process on how it should be done based on what the teacher has said as well as my own thoughts. Get input and check if its even or odd If it's odd, the board can't be filled all the way and the program ends If it's even, place a domino horizontally in the top right corner of the board Test if you can place a domino vertically in that spot. Repeat those two steps as many times as possible. The problem is I don't know how to code it to the point where you can remember the placements of each domino. I can get it to where it fills the board completely once and maybe twice, but nothing past that. I also know that I'm supposed to use recursion to figure this out fwiw. Here is the code I started on so far. There is also a main method and I have the initial even/odd check working fine. This is the part I have no idea on. public void recurDomino(int row, int column) { if (Board[2][x - 1] != false) { } else if(Board[1][x-1]!=false) { } else { for (int n=0; n < x - 1; n++) { Board[row][column] = true; Board[row][column+1] = true; column++; counter++; } recurDomino(1, 0); recurDomino(2, 0); } } Thank you for any help you guys can give me.

    Read the article

  • C++ CIN cin skips randomly

    - by user69514
    I have this program, but cin in randomly skips.. I mean sometimes it does, and sometimes it doesn't. Any ideas how to fix this? int main(){ /** get course name, number of students, and assignment name **/ string course_name; int numb_students; string assignment_name; Assignment* assignment; cout << "Enter the name of the course" << endl; cin >> course_name; cout << "Enter the number of students" << endl; cin >> numb_students; cout << "Enter the name of the assignment" << endl; cin >> assignment_name; assignment = new Assignment(assignment_name); /** iterate asking for student name and score **/ int i = 0; string student_name; double student_score = 0.0; while( i < numb_students ){ cout << "Enter the name for student #" << i << endl; cin >> student_name; cout << "Enter the score for student #" << i << endl; cin >> student_score; assignment->addScore( Student( student_name, student_score )); i++; } }

    Read the article

  • Java binary files writeUTF... explain specifications...

    - by user69514
    I'm studying Java on my own. One of the exercises is the following, however I do not really understand what it is asking to.... any smart java gurus out there that could explain this in more detail and simple words? Thanks Suppose that you have a binary file that contains numbers whos type is either int or double. You dont know the order of the numbers in the file, but their order is recorded in a string at the begining of the file. The string is composed of the letters i for int, and d for double, in the order of the types of the subsequent numbers. The string is written using the method writeUTF. For example the string "iddiiddd" indicated that the file contains eight values, as follows: one integer, followed by two doubles, followed by two integers, followed by three doubles. Read this binary file and create a new text file of the values written one to a line.

    Read the article

  • How to read values from file. tokenizer

    - by user69514
    I have a file in which each line contains two numbers. The problem is that the two number are separated by a space, but the space can be any number of blank spaces. either one, two, or more. I want to read the line and store each of the numbers in a variable, but I'm not sure how to tokenize it. i.e 1 5 3 2 5 6 3 4 83 54 23 23 32 88 8 203

    Read the article

  • UML Diagrams. When are they used?

    - by user69514
    So ok I understand that UML diagrams help for the construction of a program, but when are they used? Are they needed before you start coding? do you need them so you know what you have to code? Or do you use them after you have coded the program?

    Read the article

  • Rotate array clockwise

    - by user69514
    I have a two dimensional array that I need to rotate 90 degrees clockwise, however I keep getting arrayindexoutofbounds... public int[][] rorateArray(int[][] arr){ //first change the dimensions vertical length for horizontal length //and viceversa int[][] newArray = new int[arr[0].length][arr.length]; //invert values 90 degrees clockwise by starting from button of //array to top and from left to right int ii = 0; int jj = 0; for(int i=0; i<arr[0].length; i++){ for(int j=arr.length-1; j>=0; j--){ newArray[ii][jj] = arr[i][j]; jj++; } ii++; } return newArray; }

    Read the article

  • Java Date exception handling try catch

    - by user69514
    Is there some sort of exception in Java to catch an invalid Date object? I'm trying to use it in the following method, but I don't know what type of exception to look for. Is it a ParseException. public boolean setDate(Date date) { this.date = date; return true; }

    Read the article

  • Java add leading zeros to a number....

    - by user69514
    I need to return a string in the form xxx-xxxx where xxx is a number and xxxx is another number, however when i have leading zeros they disappear. I'm trying number formatter, but it's not working. public String toString(){ NumberFormat nf3 = new DecimalFormat("#000"); NumberFormat nf4 = new DecimalFormat("#0000"); if( areaCode != 0) return nf3.format(areaCode) + "-" + nf3.format(exchangeCode) + "-" + nf4.format(number); else return exchangeCode + "-" + number; } } I figured it out: public String toString(){ NumberFormat nf3 = new DecimalFormat("000"); NumberFormat nf4 = new DecimalFormat("0000"); if( areaCode != 0) //myFormat.format(new Integer(someValue)); return nf3.format(new Integer(areaCode)) + "-" + nf3.format(new Integer(exchangeCode)) + "-" + nf4.format(new Integer(number)); else return nf3.format(new Integer(exchangeCode)) + "-" + nf4.format(new Integer(number)); }

    Read the article

  • Java StringTokenizer, empty null tokens

    - by user69514
    I am trying to split a string into 29 tokens..... stringtokenizer won't return null tokens. I tried string.split, but I believe I am doing something wrong: String [] strings = line.split(",", 29); sample inputs: 10150,15:58,23:58,16:00,00:00,15:55,23:55,15:58,00:01,16:03,23:58,,,,,16:00,23:22,15:54,00:03,15:59,23:56,16:05,23:59,15:55,00:01,,,, 10155,,,,,,,,,,,07:30,13:27,07:25,13:45,,,,,,,,,,,07:13,14:37,08:01,15:23 10160,10:00,16:02,09:55,16:03,10:06,15:58,09:48,16:07,09:55,16:00,,,,,09:49,15:38,10:02,16:04,10:00,16:00,09:58,16:01,09:57,15:58,,,,

    Read the article

1 2 3  | Next Page >