Search Results

Search found 636 results on 26 pages for 'ab'.

Page 12/26 | < Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >

  • how to read input with multiple lines in java

    - by Gandalf StormCrow
    Hi all, Our professor is making us do some basic programming with java, he gaves a website and everything to register and submit our questions, for today I need to do this one example I feel like I'm on the right track but I just can't figure out the rest .. here is the actualy question : **Sample Input:** 10 12 10 14 100 200 **Sample Output:** 2 4 100 And here is what I've got so far : public class Practice { public static int calculateAnswer(String a, String b) { return (Integer.parseInt(b) - Integer.parseInt(a)); } public static void main(String[] args) { System.out.println(calculateAnswer(args[0], args[1])); } } Now I always get the answer 2 because I'm reading the single line, how can I take all lines into account? thank you For some strange reason everytime I want to execute I get this error: C:\sonic>java Practice.class 10 12 Exception in thread "main" java.lang.NoClassDefFoundError: Fact Caused by: java.lang.ClassNotFoundException: Fact.class at java.net.URLClassLoader$1.run(URLClassLoader.java:20 at java.security.AccessController.doPrivileged(Native M at java.net.URLClassLoader.findClass(URLClassLoader.jav at java.lang.ClassLoader.loadClass(ClassLoader.java:307 at sun.misc.Launcher$AppClassLoader.loadClass(Launcher. at java.lang.ClassLoader.loadClass(ClassLoader.java:248 Could not find the main class: Practice.class. Program will exit. Whosever version of answer I use I get this error, what do I do ? However if I run it in eclipse Run as Run Configuration - Program arguments 10 12 10 14 100 200 I get no output EDIT I have made some progress, at first I was getting the compilation error, then runtime error and now I get wrong answer , so can anybody help me what is wrong with this : import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; public class Practice { public static BigInteger calculateAnswer(String a, String b) { BigInteger ab = new BigInteger(a); BigInteger bc = new BigInteger(b); return bc.subtract(ab); } public static void main(String[] args) throws IOException { BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); String line; while ((line = stdin.readLine()) != null && line.length()!= 0) { String[] input = line.split(" "); if (input.length == 2) { System.out.println(calculateAnswer(input[0], input[1])); } } } }

    Read the article

  • Merging column headers alone in JTable

    - by Harish
    Is there a way to merge column headers on click of a button but the values in the cell should get appeneded with each other? For instance: 10 15 20 25 30 A B C D E B C D A E 10 20 30 AB CD E BC DA E Actually the value A represents 10-15 B represents 15-20 and so on.Is this possible in JTable? Please don't confuse my earlier question with this.Here we try to merge two column headers not cells at the same time we append the values of the cell.

    Read the article

  • Code Golf: Numeric Equivalent of an Excel Column-Name

    - by Vivin Paliath
    Can you figure out the numeric equivalent of an Excel column string in the shortest-possible way, using your favorite language? For example, the A column is 1, B is 2, so on and so forth. Once you hit Z, the next column becomes AA, then AB and so on. Rules: Here is some sample input and output: A: 1 B: 2 AD: 30 ABC: 731 WTF: 16074 ROFL: 326676 I don't know if the submitter is allowed to post a solution, but I have a Perl solution that clocks in at 125 characters :).

    Read the article

  • how to bind objects to gridview

    - by prince23
    hi, i am calling an webservice where my webservice is returing an object( which contains data like empid name 1 kiran 2 mannu 3 tom WebApplication1.DBLayer.Employee objEMP = ab.GetJobInfo(); now my objEMP has this collection of data empid name 1 kiran 2 mannu 3 tom how can i convert this object into( datatable or LIst) and bind to gridview thanks in advance

    Read the article

  • Simple question on ASM 8086

    - by Tal
    Hello ,I'm studying ASM 8086 at high school and I have this question: For example I have this number ABCD(hex), how is it stored on the memory? Does the AB go for example to memory address 01 and the CD goes to address 02? Thank you :-)

    Read the article

  • Help with Java Program for Prime numbers

    - by Ben
    Hello everyone, I was wondering if you can help me with this program. I have been struggling with it for hours and have just trashed my code because the TA doesn't like how I executed it. I am completely hopeless and if anyone can help me out step by step, I would greatly appreciate it. In this project you will write a Java program that reads a positive integer n from standard input, then prints out the first n prime numbers. We say that an integer m is divisible by a non-zero integer d if there exists an integer k such that m = k d , i.e. if d divides evenly into m. Equivalently, m is divisible by d if the remainder of m upon (integer) division by d is zero. We would also express this by saying that d is a divisor of m. A positive integer p is called prime if its only positive divisors are 1 and p. The one exception to this rule is the number 1 itself, which is considered to be non-prime. A positive integer that is not prime is called composite. Euclid showed that there are infinitely many prime numbers. The prime and composite sequences begin as follows: Primes: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, … Composites: 1, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24, 25, 26, 27, 28, … There are many ways to test a number for primality, but perhaps the simplest is to simply do trial divisions. Begin by dividing m by 2, and if it divides evenly, then m is not prime. Otherwise, divide by 3, then 4, then 5, etc. If at any point m is found to be divisible by a number d in the range 2 d m-1, then halt, and conclude that m is composite. Otherwise, conclude that m is prime. A moment’s thought shows that one need not do any trial divisions by numbers d which are themselves composite. For instance, if a trial division by 2 fails (i.e. has non-zero remainder, so m is odd), then a trial division by 4, 6, or 8, or any even number, must also fail. Thus to test a number m for primality, one need only do trial divisions by prime numbers less than m. Furthermore, it is not necessary to go all the way up to m-1. One need only do trial divisions of m by primes p in the range 2 p m . To see this, suppose m 1 is composite. Then there exist positive integers a and b such that 1 < a < m, 1 < b < m, and m = ab . But if both a m and b m , then ab m, contradicting that m = ab . Hence one of a or b must be less than or equal to m . To implement this process in java you will write a function called isPrime() with the following signature: static boolean isPrime(int m, int[] P) This function will return true or false according to whether m is prime or composite. The array argument P will contain a sufficient number of primes to do the testing. Specifically, at the time isPrime() is called, array P must contain (at least) all primes p in the range 2 p m . For instance, to test m = 53 for primality, one must do successive trial divisions by 2, 3, 5, and 7. We go no further since 11 53 . Thus a precondition for the function call isPrime(53, P) is that P[0] = 2 , P[1] = 3 , P[2] = 5, and P[3] = 7 . The return value in this case would be true since all these divisions fail. Similarly to test m =143 , one must do trial divisions by 2, 3, 5, 7, and 11 (since 13 143 ). The precondition for the function call isPrime(143, P) is therefore P[0] = 2 , P[1] = 3 , P[2] = 5, P[3] = 7 , and P[4] =11. The return value in this case would be false since 11 divides 143. Function isPrime() should contain a loop that steps through array P, doing trial divisions. This loop should terminate when 2 either a trial division succeeds, in which case false is returned, or until the next prime in P is greater than m , in which case true is returned. Function main() in this project will read the command line argument n, allocate an int array of length n, fill the array with primes, then print the contents of the array to stdout according to the format described below. In the context of function main(), we will refer to this array as Primes[]. Thus array Primes[] plays a dual role in this project. On the one hand, it is used to collect, store, and print the output data. On the other hand, it is passed to function isPrime() to test new integers for primality. Whenever isPrime() returns true, the newly discovered prime will be placed at the appropriate position in array Primes[]. This process works since, as explained above, the primes needed to test an integer m range only up to m , and all of these primes (and more) will already be stored in array Primes[] when m is tested. Of course it will be necessary to initialize Primes[0] = 2 manually, then proceed to test 3, 4, … for primality using function isPrime(). The following is an outline of the steps to be performed in function main(). • Check that the user supplied exactly one command line argument which can be interpreted as a positive integer n. If the command line argument is not a single positive integer, your program will print a usage message as specified in the examples below, then exit. • Allocate array Primes[] of length n and initialize Primes[0] = 2 . • Enter a loop which will discover subsequent primes and store them as Primes[1] , Primes[2], Primes[3] , ……, Primes[n -1] . This loop should contain an inner loop which walks through successive integers and tests them for primality by calling function isPrime() with appropriate arguments. • Print the contents of array Primes[] to stdout, 10 to a line separated by single spaces. In other words Primes[0] through Primes[9] will go on line 1, Primes[10] though Primes[19] will go on line 2, and so on. Note that if n is not a multiple of 10, then the last line of output will contain fewer than 10 primes. Your program, which will be called Prime.java, will produce output identical to that of the sample runs below. (As usual % signifies the unix prompt.) % java Prime Usage: java Prime [PositiveInteger] % java Prime xyz Usage: java Prime [PositiveInteger] % java Prime 10 20 Usage: java Prime [PositiveInteger] % java Prime 75 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 % 3 As you can see, inappropriate command line argument(s) generate a usage message which is similar to that of many unix commands. (Try doing the more command with no arguments to see such a message.) Your program will include a function called Usage() having signature static void Usage() that prints this message to stderr, then exits. Thus your program will contain three functions in all: main(), isPrime(), and Usage(). Each should be preceded by a comment block giving it’s name, a short description of it’s operation, and any necessary preconditions (such as those for isPrime().) See examples on the webpage.

    Read the article

  • Draw Lines Over a Circle

    - by VOX
    There's a line A-B and C at the center between A and B. It forms a circle as in the figure. If we assume A-B line as a diameter of the circle and then C is it's center. My problem is I have no idea how to draw another three lines (in blue) each 45 degree away from AC or AB. No, this is not a homework, it's part of my complex geometry in a rendering. http://www.freeimagehosting.net/image.php?befcd84d8c.png

    Read the article

  • Generate all unique substrings for given string

    - by Yuval A
    Given a string s, what is the fastest method to generate a set of all its unique substrings? Example: for str = "aba" we would get substrs={"a", "b", "ab", "ba", "aba"}. The naive algorithm would be to traverse the entire string generating substrings in length 1..n in each iteration, yielding an O(n^2) upper bound. Is a better bound possible? (this is technically homework, so pointers-only are welcome as well)

    Read the article

  • How do I programmatically convert mp3 to an itunes-playable aac/m4a file?

    - by kwork
    I've been looking for a way to convert an mp3 to aac programmatically or via the command line with no luck. Ideally, I'd have a snippet of code that I could call from my rails app that converts an mp3 to an aac. I installed ffmpeg and libfaac and was able to create an aac file with the following command: ffmpeg -i test.mp3 -acodec libfaac -ab 163840 dest.aac When i change the output file's name to dest.m4a, it doesn't play in iTunes. Thanks!

    Read the article

  • Regex with all optional parts but at least one required

    - by Alan Mendelevich
    I need to write a regex that matches strings like "abc", "ab", "ac", "bc", "a", "b", "c". Order is important and it shouldn't match multiple appearances of the same part. a?b?c? almost does the trick. Except it matches empty strings too. Is there any way to prevent it from matching empty strings or maybe a different way to write a regex for the task.

    Read the article

  • list of polymorphic objects

    - by LivingThing
    I have a particular scenario below. The code below should print 'say()' function of B and C class and print 'B says..' and 'C says...' but it doesn't .Any ideas.. I am learning polymorphism so also have commented few questions related to it on the lines of code below. class A { public: // A() {} virtual void say() { std::cout << "Said IT ! " << std::endl; } virtual ~A(); //why virtual destructor ? }; void methodCall() // does it matters if the inherited class from A is in this method { class B : public A{ public: // virtual ~B(); //significance of virtual destructor in 'child' class virtual void say () // does the overrided method also has to be have the keyword 'virtual' { cout << "B Sayssss.... " << endl; } }; class C : public A{ public: //virtual ~C(); virtual void say () { cout << "C Says " << endl; } }; list<A> listOfAs; list<A>::iterator it; # 1st scenario B bObj; C cObj; A *aB = &bObj; A *aC = &cObj; # 2nd scenario // A aA; // B *Ba = &aA; // C *Ca = &aA; // I am declaring the objects as in 1st scenario but how about 2nd scenario, is this suppose to work too? listOfAs.insert(it,*aB); listOfAs.insert(it,*aC); for (it=listOfAs.begin(); it!=listOfAs.end(); it++) { cout << *it.say() << endl; } } int main() { methodCall(); retrun 0; }

    Read the article

  • What are the Ruby equivalent of Python itertools, esp. combinations/permutations/groupby?

    - by Amadeus
    Python's itertools module provides a lots of goodies with respect to processing an iterable/iterator by use of generators. For example, permutations(range(3)) --> 012 021 102 120 201 210 combinations('ABCD', 2) --> AB AC AD BC BD CD [list(g) for k, g in groupby('AAAABBBCCD')] --> AAAA BBB CC D What are the equivalent in Ruby? By equivalent, I mean fast and memory efficient (Python's itertools module is written in C).

    Read the article

  • ffmpeg libxvid settings for optimal quality and preferably fast encoding

    - by dropson
    What ffmpeg settings should I use to convert a video into xvid with a mixed speed and quality ratio, using 2-passes, and alternativly 1 pass. Currently I use the following for just 1 pass, but I need a better sugestion. -acodec libmp3lame -ab 128 -ar 44100 -ac 2 -vcodec libxvid -qmin 3 -qmax 5 -mbd 2 -bf 2 -flags +4mv -trellis -aic -cmp 2 -subcmp 2 -g 2 -maxrate 1300 -b 1200 -threads 0

    Read the article

  • Finding what makes strings unique in a list, can you improve on brute force?

    - by Ed Guiness
    Suppose I have a list of strings where each string is exactly 4 characters long and unique within the list. For each of these strings I want to identify the position of the characters within the string that make the string unique. So for a list of three strings abcd abcc bbcb For the first string I want to identify the character in 4th position d since d does not appear in the 4th position in any other string. For the second string I want to identify the character in 4th position c. For the third string it I want to identify the character in 1st position b AND the character in 4th position, also b. This could be concisely represented as abcd -> ...d abcc -> ...c bbcb -> b..b If you consider the same problem but with a list of binary numbers 0101 0011 1111 Then the result I want would be 0101 -> ..0. 0011 -> .0.. 1111 -> 1... Staying with the binary theme I can use XOR to identify which bits are unique within two binary numbers since 0101 ^ 0011 = 0110 which I can interpret as meaning that in this case the 2nd and 3rd bits (reading left to right) are unique between these two binary numbers. This technique might be a red herring unless somehow it can be extended to the larger list. A brute-force approach would be to look at each string in turn, and for each string to iterate through vertical slices of the remainder of the strings in the list. So for the list abcd abcc bbcb I would start with abcd and iterate through vertical slices of abcc bbcb where these vertical slices would be a | b | c | c b | b | c | b or in list form, "ab", "bb", "cc", "cb". This would result in four comparisons a : ab -> . (a is not unique) b : bb -> . (b is not unique) c : cc -> . (c is not unique) d : cb -> d (d is unique) or concisely abcd -> ...d Maybe it's wishful thinking, but I have a feeling that there should be an elegant and general solution that would apply to an arbitrarily large list of strings (or binary numbers). But if there is I haven't yet been able to see it. I hope to use this algorithm to to derive minimal signatures from a collection of unique images (bitmaps) in order to efficiently identify those images at a future time. If future efficiency wasn't a concern I would use a simple hash of each image. Can you improve on brute force?

    Read the article

  • how to make my code scalable on iphone ..thanks

    - by zjm1126
    this is my code: <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width,minimum-scale=0,maximum-scale=2.0><!--,user-scalable=no">--> </head> <body onorientationchange="updateOrientation();"> <div id="a"> <input id='ab' type="button" value="button" /> </div> <div id=b style="display: none"></div> <style type="text/css"> *{ margin:0; padding:0; } body{ /*height: 356px;* } /* Reposition on orientation change */ body.landscape{ height: 208px; } body.landscape div#a{ line-height:104px; } div#a{ height:50%; line-height:178px; text-align:center; } #b{ width:100%; height:50%; background:red; } </style> <script src="jquery-1.4.2.js" type="text/javascript"></script> <script type="text/javascript"> function updateOrientation() { var orientation = window.orientation; switch (orientation) { // If we're horizontal case 90: case -90: // Set orient to landscape $(document.body).addClass("landscape"); break; // If we're vertical default: // Set orient to portrait $(document.body).removeClass("landscape"); break; } } $('#ab').click(function(){ if($('#b').css('display')=='none')$('#b').css('display','block') else $('#b').css('display','none') }) </script> </body> </html> thanks

    Read the article

  • JavaScript: using constructor without operator 'new'

    - by GetFree
    Please help me to understand why the following code works: <script> var re = RegExp('\\ba\\b') ; alert(re.test('a')) ; alert(re.test('ab')) ; </script> In the first line there is no new operator. As far as I know, a contructor in JavaScript is a function that initialize objects created by the operator new and they are not meant to return anything.

    Read the article

  • Numeric equivalent of an Excel column name

    - by Vivin Paliath
    The challenge The shortest code by character count that will output the numeric equivalent of an Excel column string. For example, the A column is 1, B is 2, so on and so forth. Once you hit Z, the next column becomes AA, then AB and so on. Test cases: A: 1 B: 2 AD: 30 ABC: 731 WTF: 16074 ROFL: 326676 Code count includes input/output (i.e full program).

    Read the article

  • How can I query Google Spreadsheets API with a string value?

    - by ColinM
    I am using Zend_Gdata_SpreadsheetsListQuery. In PHP my query is: "confirmation=$confirmation" The problem is that $confirmation = 'AB-CD-EFG-012345'; Apparently the hyphens are causing problems with the query and the exception thrown is: Uncaught exception 'Zend_Gdata_App_HttpException' with message 'Expected response code 200, got 400 Parse error: Invalid token encountered' How can I quote or escape the value to not cause parse errors? Single quotes cause the same error, double quotes don't throw errors but there are no results to match.

    Read the article

  • did you know some good web site about 'iphone css layouts' ,and can you help me to improve my code..

    - by zjm1126
    i want to create a webpage on iphone , but i can't complete it in a simple way, this is my code: <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=5.0,user-scalable=yes"> </head> <body onorientationchange="updateOrientation();" onload=updateOrientation()> <div id="a"> <input id='ab' type="button" value="button" /> </div> <div id=b style="display: none">sssadwq dwqdqw</div> <style type="text/css"> *{ margin:0; padding:0; } /* Reposition on orientation change */ body.landscape{ height: 268px; } body.landscape #a{ height:134px; line-height:134px; } body.landscape #b{ height:114px; width:470px; } body{ height: 416px; } #a{ line-height:208px; height:208px; text-align:center; } #b{ height:198px; width:310px; background:red; border:5px solid black; } </style> <script src="jquery-1.4.2.js" type="text/javascript"></script> <script type="text/javascript"> function updateOrientation() { var orientation = window.orientation; switch (orientation) { // If we're horizontal case 90: case -90: // Set orient to landscape $(document.body).addClass("landscape"); break; // If we're vertical default: // Set orient to portrait $(document.body).removeClass("landscape"); break; } } $('#ab').click(function(){ if($('#b').css('display')=='none')$('#b').css('display','block') else $('#b').css('display','none') }) </script> </body> </html> it use much more fixed number,this is not the best way ,i think the best way is to use the percentage more and more, can you do it fo me ,, thanks

    Read the article

  • how to use time out in mplayer?

    - by manoj
    I am trying to save audio using mplayer from a live http stream. saving audio is successful. If there is no live stream playing it does not exit automatically. Is there any way to set timeout if there is no live stream? code : mplayer -i url -t 00:00:10 -acodec libmp3lame -ab 24 -ar 8000 audio.mp3 Thanks in advance.

    Read the article

< Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >