Search Results

Search found 3773 results on 151 pages for 'args'.

Page 82/151 | < Previous Page | 78 79 80 81 82 83 84 85 86 87 88 89  | Next Page >

  • What does this recursive function do?

    - by null
    What does this function do? And how do you evaluate it? How to trace it? How to understand recursive method? I just can't understand the recursion, and the exam date is coming soon, and I know in order to understand recursion, I must first understand recursion. But I just can't write a slightly complex recursive method, can anyone help me out using the simplest English words. public class BalancedStrings { public static void printBalanced(String prefix, int a, int b) { if (a > 0) printBalanced(prefix + "a", a - 1, b); if (b > 0) printBalanced(prefix + "b", a, b - 1); if (a == 0 && b == 0) System.out.println(prefix); } public static void printBalanced(int n) { if (n % 2 == 0) { printBalanced("", n / 2, n / 2); } } public static void main(String[] args) { printBalanced(4); } }

    Read the article

  • program to determine number of duplicates in a sentence

    - by bhavna raghuvanshi
    public class duplicate { public static void main(String[] args)throws IOException { System.out.println("Enter words separated by spaces ('.' to quit):"); Set<String> s = new HashSet<String>(); Scanner input = new Scanner(System.in); while (true) { String token = input.next(); if (".".equals(token)) break; if (!s.add(token)) System.out.println("Duplicate detected: " + token); } System.out.println(s.size() + " distinct words:\n" + s); } } my program detects and prints duplicate words but i need to print the number of duplicate words also. pls help me do it.

    Read the article

  • Run .exe packaged in .jar

    - by user1471327
    I am trying to merge 2 programs I have made to one .jar file. One program is a .jar written in java and the second one is an .exe written in c++. I put both files to the new .jar, wrote this code but it didn't work. When this code was exported to .jar and executed neither of 2 files ran and I got error "no main manifest attribute, in merged.jar" in cmd. Though it worked perfectly when run in eclipse. public class main { public static void main(String[] args) { try { Runtime.getRuntime().exec("cmd /c project1.jar"); Runtime.getRuntime().exec("cmd /c project2.exe"); } catch(Exception exce) { /*handle exception*/ } } } Any idea how to fix this or is there another way to do it? I am new to java, so can't think of anything good. Maybe it would be possible to drop these files to a temporary location in windows and delete them after they're executed?

    Read the article

  • Use of class definitions inside a method in Java

    - by Bragaadeesh
    Hi public class TestClass { public static void main(String[] args) { TestClass t = new TestClass(); } private static void testMethod(){ class TestMethodClass{ int a; int b; int c; } TestMethodClass testMethodClass = new TestMethodClass(); } } I found out that the above piece of code is perfectly legal in Java. I have the following questions. What is the use of ever having a class definition inside a method? Will a class file be generated for TestMethodClass Its hard for me to imagine this concept in an Object Oriented manner. Having a class definition inside a behavior. Probably can someone tell me with equivalent real world examples. Thanks

    Read the article

  • Adding a html file into a c# email app

    - by neilos
    using System; using System.Net; using System.Net.Mail; class MainClass { public static void Main(string[] args) { SmtpClient client = new SmtpClient("192.168.1.12", 25); using (MailMessage msg = new MailMessage()) { msg.From = new MailAddress("[email protected]"); msg.Subject = "***Dexter DB***"; msg.Body = "***DB backup done***"; // I want to change this so i can do this in html file - how do i pick up this file and send a html form? msg.To.Add(new MailAddress("[email protected]")); client.Send(msg); } } }

    Read the article

  • Call function based off of a string in Lisp

    - by powerj1984
    I am passing in command line arguments to my Lisp program and they are formatted like this when they hit my main function: ("1 1 1" "dot" "2 2 2") I have a dot function and would like to call it directly from the argument, but this isn't possible because something like (funcall (second args)...) receives "dot" and not dot as the function name. I tried variations of this function: (defun remove-quotes (s) (setf (aref s 0) '"")) to no avail, before realizing that the quotes were not really a part of the string. Is there a simple way to do this, or should I just check each string and then call the appropriate function? Thanks!

    Read the article

  • What is the best way to identify that a function returned and automatically do something with it?

    - by EpsilonVector
    I'm implementing user threads on a Linux 2.4 kernel (homework) and my threads are basically just functions running with their own execution context (for example: uthread_create(functionpointer, args)). I'm having a hard time figuring out how to catch the return value and have it ready to be returned when two threads join. I know where to get the value from (eax), but not how to identify that the function actually finished. There's something called atexit, but I've seen people advising against using it, so... what is the best way to discover that a function returned and do something about it?

    Read the article

  • is the + in += on a Map a prefix operator of =?

    - by Steve
    In the book "Programming in Scala" from Martin Odersky there is a simple example in the first chapter: var capital = Map("US" -> "Washington", "France" -> "Paris") capital += ("Japan" -> "Tokyo") The second line can also be written as capital = capital + ("Japan" -> "Tokyo") I am curious about the += notation. In the class Map, I didn't found a += method. I was able to the same behaviour in an own example like class Foo() { def +(value:String) = { println(value) this } } object Main { def main(args: Array[String]) = { var foo = new Foo() foo = foo + "bar" foo += "bar" } } I am questioning myself, why the += notation is possible. It doesn't work if the method in the class Foo is called test for example. This lead me to the prefix notation. Is the + a prefix notation for the assignment sign (=)? Can somebody explain this behaviour?

    Read the article

  • php string to array and split

    - by RussP
    Hi folks Looking for suggestions as to the best way to do this (I know there are many options): take a variable like this: $args = ('post_type=post&order_by=DESC&limit=10'); the create a function to convert that variable into parts like this: $post_type = post; $order_by = DESC; $limit= 10; Reason is I want a client to be able to use a string like the first to pass variables to a sql query in much the same way (but doesn't have to be exact) as you can do it in WordPress.

    Read the article

  • Simple Java math operations

    - by user1730056
    I'm making a BMI calculator that doesn't seem to be working. The math operations work if i just do something like w/h, but once i had the brackets, it returns an error. If i change the variables w and h and use a constant number, the operation works. Another problem is that although i'm making result a double, it seems to be rounding to the nearest int. Could someone tell me what I'm doing wrong here? public class ass10 { public static void main(String[] args) { bmi(223,100); } public static bmi(int w, int h){ double result; result = (w/(h*h))*703 System.out.println(result) } }

    Read the article

  • Numeric GUI bottleneck

    - by Physic
    Hi all, I've made a GUI to set up and start a numerical integrator using PyQT4, Wing, QT, and Python 2.6.6, on my Mac. The thing is, when I run the integrator form the GUI, it takes very many times longer than when I crudely run the integrator from the command line. As an example, a 1000 year integration took 98 seconds on the command line and ~570 seconds from the GUI. In the GUI, the integration runs from a thread and then returns. It uses a a queue to communicate back to the GUI. Does anyone have any ideas as to where the bottleneck is? I suspect that others may be experiencing something like this just on a smaller scale. t = threading.Thread( target=self.threadsafe_start_thread, args=( self.queue, self.selected ) ) t.start() Thanks!

    Read the article

  • C# Console Application Output to .csv file

    - by Zinn
    I am trying to make a program that will show the numbers: 1, 10 +30 2, 40 (the scale goes up in this pattern by adding 20 to the last number added) 3, 90 +50 4, 160 5, 250 +70 So far I have this code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO;// namespace Myloop { class Program { static void Main(string[] args) /// </summary> { StreamWriter myOutputStream = new StreamWriter("loopdata.csv"); int forloop; for (forloop = 1; forloop < 21; forloop++) Console.WriteLine(forloop); Console.ReadLine(); myOutputStream.Close(); } } } This is showing the first sequence of numbers 1 - 20, but could anyone give me any guidance how to do the other sequence next to it in the console application and how I can output these to a .csv file, as the information I have so far doesn't appear in the .csv file

    Read the article

  • How to ignore an exception and continue processing a foreach loop?

    - by Barry Dysert
    I have a test program that is supposed to loop over all the files under C:. It dies when it hits the "Documents and Settings" folder. I'd like to ignore the error and keep looping over the remaining files. The problem is that the exception is thrown in the foreach, so putting a try/catch around the foreach will cause the loop to exit. And putting a try/catch after the foreach never fires (because the exception is thrown in the foreach). Is there any way to ignore the exception and continue processing the loop? Here's the code: static void Main(string[] args) { IEnumerable<string> files = Directory.EnumerateFiles(@"C:\", "*.*", SearchOption.AllDirectories); foreach (string file in files) // Exception occurs when evaluating "file" Console.WriteLine(file); }

    Read the article

  • C# compiler fails to recognize a class is implementing an interface

    - by Freek
    The following code fails to compile (using VS2010) and I don't see why. The compiler should be able to infer that List is 'compatible' (sorry for lack of a better word) with IEnumerable, but somehow it doesn't. What am I missing here? interface ITest { void Test(); } class TestClass : ITest { public void Test() { } } class Program { static void Test(IEnumerable<ITest> tests) { foreach(var t in tests) { Console.WriteLine(t); } } static void Main(string[] args) { var lst = new List<TestClass>(); Test(lst); // fails, why? Test(lst.Select(t=>t as ITest)); //success Test(lst.ToArray()); // success } }

    Read the article

  • what the java command's -jar option really does

    - by JBoy
    Does the -jar option of the java command also compile the sources before running the main method? I believe so but i would like to have a better understanding of the internal process, from the man page you can clearly see a small workflow sequence: -jar Execute a program encapsulated in a JAR file. The first argument is the name of a JAR file instead of a startup class name. In order for this option to work, the manifest of the JAR file must contain a line of the form Main-Class: classname. Here, classname identifies the class having the public static void main(String[] args) method that serves as your application's starting point. See the Jar tool reference page and the Jar trail of the Java Tutorial @ But it does not mention that it compiles the sources.

    Read the article

  • question on revrse array

    - by davit-datuashvili
    we know algorithm how reverse array of n integers for (int i=0;i<n/2;i++){ swap(a[i],a[n-1-i]): } is this method better according the speed of algorithm or not because swap using xor is more fast then in other method here is code public class swap{ public static void main(String[]args){ int a[]=new int[]{2,4,5,7,8,11,13,12,14,24}; System.out.println(" array at the begining:"); for (int i=0;i<a.length;i++){ System.out.println(a[i]); } for (int j=0;j<a.length/2;j++){ a[j]^=a[a.length-1-j]; a[a.length-1-j]^=a[j]; a[j]^=a[a.length-1-j]; } System.out.println("reversed array:"); for (int j=0;j<a.length;j++){ System.out.println(a[j]); } } } //result array at the begining: 2 4 5 7 8 11 13 12 14 24 reversed array: 24 14 12 13 11 8 7 5 4 2

    Read the article

  • i have done code so please help

    - by davit-datuashvili
    public class bitap{ public static void main(String[]args){ String text="tbillisi"; String pattern="tbilxiri"; int k=2; int m=pattern.length(); long pattern_mask[]=new long[Character.MAX_VALUE+1]; String result=""; boolean[]R=new boolean[m+1]; long i,d; for (i=0;i<=k;i++){ R[i]=~1; } for (i=0;i if (0==(R[k]& (1< System.out.println(result); } } http://en.wikipedia.org/wiki/Bitap_algorithm from this site

    Read the article

  • When debugging in VS 2008 why does the debugger land on a second return statement?

    - by Hellfire
    When debugging the following console program: class Program { static void Main(string[] args) { Console.WriteLine(DoIt(false)); Console.WriteLine(DoIt(true)); } private static Boolean DoIt(Boolean abort) { try { throw new InvalidOperationException(); } catch(Exception ex) { if (abort) { return true; } Console.WriteLine("Got here"); return false; } } } Why does the IDE land on the second return statement during the second call to DoIt()? The results of the execution is correct but the debugging experience is misleading. Is this a known issue? Is the behavior in VS 2010 the same?

    Read the article

  • Can anybody explain the working of following code...?

    - by Siddhi
    Can anybody explain the working of following code...? interface myInterface{} public class Main { public static void main(String[] args) { System.out.println(new myInterface(){public String toString(){return "myInterfacetoString";}}); System.out.println(new myInterface(){public String myFunction(){return "myInterfacemyFunction";}}); } } Output is... myInterfacetoString primitivedemo.Main$2@9304b1 All answers saying that myInterface in println() statement is anonymous class. But as I already declared it as an interface, why does it allow me to create anonymous class of same name....? again...if these are anonymous classes then class main should allow me to give any name to these anonymous classes..But if try to do so..I'm getting compilation error

    Read the article

  • C# - opening process and changing window position

    - by bartq
    I want to open from c# an application (standalone flashplayer) and set it position to (0,0) on the screen. How can I do this? So far I've managed to open flashplayer: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; namespace swflauncher { class Program { static void Main(string[] args) { Process flash = new Process(); flash.StartInfo.WindowStyle = ProcessWindowStyle.Normal; flash.StartInfo.FileName = "D:\\development\\flex4\\runtimes\\player\\10\\win\\FlashPlayer.exe"; flash.Start(); } } }

    Read the article

  • please help me to solve problem

    - by davit-datuashvili
    i have operation on heap fixdown operation below is code public class HEap{ public static void fixdown(int a[],int k,int n){ while(2*k<=n){ int j=2*k; if (j<n && a[j]<a[j+1]) j++; if (!(a[k]<a[j])) break; int t=a[k]; a[k]=a[j]; a[j]=k; k=j; } } public static void main(String[]args){ int a[]=new int[]{12,15,20,29,23,22,17,40,26,35,19,51}; fixdown(a,1,a.length); for (int i=0;i<a.length;i++){ System.out.println(a[i]); } } } //and result is 12 29 20 40 23 22 17 3 26 35 19 51 i am interested why is 3 in the list?in the array is not

    Read the article

  • is this code correct? [closed]

    - by davit-datuashvili
    hi i have poste this code from this title http://stackoverflow.com/questions/2896363/hi-i-have-question-here-is-pseudo-code-about-sift-up-and-sift-down-on-heaps i have following code of siftup on heap is it correct?i have put here because i have changed at old place my question and it became unreadable so i have posted here public class siftup{ public static void main(String[]args){ int p; int n=12; int a[]=new int[]{15,20,12,29,23,17,22,35,40,26,51,19}; int i=n-1; while (i!=0){ if (i==1) break; p=i/2; if (a[p]<=a[i]){ int t=a[p]; a[p]=a[i]; a[i]=t; } i=p; } for (int j=0;j<n;j++){ System.out.println(a[j]); } } } //result is this 15 20 19 29 23 12 22 35 40 26 51 17 is it correct?

    Read the article

  • Why does GC.GetTotalMemory() report huge memory allocations?

    - by Seventh Element
    I have been playing around with GC.GetTotalMemory(). When I create a local variable of type Titles in the example below, the consumed amount of memory increases by 6276 bytes. What's going on here? class Program { enum Titles { Mr, Ms, Mrs, Dr }; static void Main(string[] args) { GetTotalMemory(); Titles t = Titles.Dr; GetTotalMemory(); } static void GetTotalMemory() { long bytes = GC.GetTotalMemory(true); Console.WriteLine("{0}", bytes); } }

    Read the article

  • Java Collections.Rotate with an array doesn't work

    - by steve_72
    I have the following java code: import java.util.Arrays; import java.util.Collections; public class Test { public static void main(String[] args) { int[] test = {1,2,3,4,5}; Collections.rotate(Arrays.asList(test), -1); for(int i = 0; i < test.length; i++) { System.out.println(test[i]); } } } I want the array to be rotated, but the output I get is 1 2 3 4 5 Why is this? And is there an alternative solution?

    Read the article

  • Java Double Array

    - by user1062058
    I'm having trouble setting up and placing values into an array using a text file containing the floating point numbers 2.1 and 4.3 each number is separated by a space - below is the error I'm getting: Exception in thread "main" java.util.NoSuchElementException import java.util.*; import java.io.*; public class DoubleArray { public static void main(String[] args) throws FileNotFoundException { Scanner in = new Scanner(new FileReader("mytestnumbers.txt")); double [] nums = new double[2]; for (int counter=0; counter < 2; counter++) { int index = 0; index++; nums[index] = in.nextDouble(); } } } Thanks, I'm sure this isn't a hard question to answer... I appreciate your time.

    Read the article

< Previous Page | 78 79 80 81 82 83 84 85 86 87 88 89  | Next Page >