Need Help writing program
very new to java, i conceptually know what i want to do, but it is hard to apply that to writing the program. this is very introductory so i'd appreciate all and any help.
i am trying to write a program such that if I select an integer, n, as in input, the program can convert that integer into it's binary representation. for example, if the integer is 4, then the program would output 001 as the binary representation of 4.
that is the first part, the second part is to have the binary representation go from most significan bit to least significant bit, so for the integer 4 it will come out as 100 (or 000100 or 00100).
ok basically i know i want the program to divide the chosen integer by 2 and take the remainder (n%2), which will be 1 or 0. i then want the program to take the value (n/2) and have that be the new n value, then repeat the steps over and over till my n just becomes 0. i am trying to do this with a while loop, but if there is an easier way to do this, please let me know. so far wha ti have is below, kinda stuck on how to write this program, please help. the output just keeps giving me 0 and doesn't end.
import java.util.*;
class Q3a{
static Scanner console = new Scanner (System.in);
public static void main(String args[]){
int n;
n = console.nextInt();
System.out.print("Choose an integer value :");
while (true) {
System.out.println("Remainder on dividing " + n + " by 2 is " + n%2);
n = n/2;}
System.out.println("New value of n is n/2 which is " + n);
System.out.println("Remainder on dividing " + n + " by 2 is " + n%2);
n = n/2;
System.out.println("New value of n is n/2 which is " + n);
System.out.println("Remainder on dividing " + n + " by 2 is " + n%2);
n = n/2;
System.out.println("New value of n is n/2 which is " + n);Message was edited by:
kribraider414
consider
while (n != 0){
System.out.println(n%2);
n = n/2;
}put the reverse of the stoping condition in the parens for the loop
This loop will run while n is NOT zero. It wil stop when n is zero. Try it for a few numbers and see what it does.
Pay particular attention to what it does if the number you supplied is zero (which is the one binary number that does not have a single one in it.)
Also take a look at what it does for negative numbers and decide what you want to do in that case.
Similar Messages
-
Need help writing host program using LabView.
Need help writing host program using LabView.
Hello,
I'm designing a HID device, and I want to write a host program using National Instrument's LabView. NI doesn't have any software support for USB, so I'm trying to write a few C dll files and link them to Call Library Functions. NI has some documentation on how to do this, but it's not exactly easy reading.
I've written a few C console programs (running Win 2K) using the PC host software example for a HID device from John Hyde's book "USB by design", and they run ok. From Hyde's example program, I've written a few functions that use a few API functions each. This makes the main program more streamlined. The functions are; GetHIDPath, OpenHID, GetHIDInfo, Writ
eHID, ReadHIC, and CloseHID. As I mentioned, my main program runs well with these functions.
My strategy is to make dll files from these functions and load them into LabView Call Library Functions. However, I'm having a number of subtle problems in trying to do this. The big problem I'm having now are build errors when I try to build to a dll.
I'm writing this post for a few reasons. First, I'm wondering if there are any LabView programmers who have already written USB HID host programs, and if they could give me some advice. Or, I would be grateful if a LabView or Visual C programmer could help me work out the programming problems that I'm having with my current program. If I get this LabView program working I would be happy to share it. I'm also wondering if there might already be any USB IHD LabView that I could download.
Any help would be appreciated.
Regards, George
George Dorian
Sutter Instruments
51 Digital DR.
Novato, CA 94949
USA
[email protected]
m
(415) 883-0128
FAX (415) 883-0572George may not answer you. He hasn't been online here for almost eight years.
Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice -
Need help writing small program!
Hi. I'm learning Java programming, and I need help writing a small program. Please someone help me.
Directions:
Create a program called CerealCompare using an if-then-else structure that obtains the price and number of ounces in a box for two boxes of cereal. The program should then output which box costs less per ounce.class CerealCompare {
public static void main(String[] args) {
// your code goes here
}Hope that helps.
P.S. Java does not have an if-then-else statement. -
Need Help Writing Server side to submit form via API
Hey
I need help writing a serverside application to submit
information via API to a separate server.
I have a client that uses constant contact for email
campaigns. We want to add to her website a form taht submits the
information needed to subscribe to her email list, to constant
contact via API.
FORM.asp :: (i got this one under control)
name
email
and submits to serverside.asp
SERVERSIDE.ASP
In serverside.asp i need to have
the API URL
(https://api.constantcontact.com/0.1/API_AddSiteVisitor.jsp)
username (of the constant contact account)
password (of the constant contact account)
name (submited from form.asp)
email (submitted from form.asp)
redirect URL (confirm.asp)
Can anyone help get me going in the right direction?
i have tried several things i found on the net and just cant
get anyone to work correctly.
One main issue i keep having is that if i get it to submit to
the API url correctly - i get a success code, it doesnt redirect to
the page i am trying to redirect to.
ASP or ASP.NET code would be find.
THANKS
sam> This does require server side programming.
> if you dont know what that is, then you dont know the
answer to my question. I
> know what i need to do - i just dont know HOW to do it.
If you are submitting a form to a script on a remote server,
and letting
that script load content to the browser, YOU have no control
over what it
loads UNLESS there is some command you can send it that it
will understand.
No amount of ASP on your server is going to change what the
remote script
does.
http://www.constantcontact.com/services/api/index.jsp
they only allow their customers to see the instructions for
the API so i
can't search to see IF there is a redirect you can send with
the form info.
But posts on their support board say that there is.
Alan
Adobe Community Expert, dreamweaver
http://www.adobe.com/communities/experts/ -
I need help writing a script that finds the first instance of a paragraph style and then changes it
I need help writing a script that finds the first instance of a paragraph style and then changes it to another paragraph style. I don't necessarily need someone to write the whole thing, by biggest problem is figuring how to find just the first instance of the paragraph style. Any help would be greatly appreciated, thanks!
Hi,
Do you mean first instance of the paragraph style
- in a chosen story;
- on some chosen page in every text frames, looking from its top to the bottom;
- in a entire document, looking from its beginning to the end, including hidden layers, master pages, footnotes etc...?
If story...
You could set app.findTextPreferences.appliedParagraphStyle to your "Style".
Story.findText() gives an array of matches. 1st array's element is a 1st occurence.
so:
Story.findText()[0].appliedParagraphStyle = Style_1;
//==> this will change a paraStyle of 1st occurence of story to "Style_1".
If other cases...
You would need to be more accurate.
rgds -
Need help writing Labview Program!!!!!
I have a labview project that needs to be finished. I was not the original creator of the program and the guy who created no longer is involved with the project and I am left to finish it. Could you make the final adjustment so I can turn this into my professor and get the final grade. Thanks! Willing to pay! Negeotiable price!!!!!!!!
Need help completing assignment! Could anyone assist me in this project!
Attachments:
dial tone detection.zip 1253 KB -
Need help writing a query for following scenario
Hi all, I need some help writing a query for the following case:
One Table : My_Table
Row Count: App 5000
Columns of Interest: AA and BB
Scenario: AA contains some names of which BB contains the corresponding ID. Some
names are appearing more than once with different IDs. For example,
AA BB
Dummy 10
Me 20
Me 30
Me 40
You 70
Me 50
Output needed: I need to write a query that will display only all the repeating names with their corresponding IDs excluding all other records.
I would appreciate any input. ThanksIs it possible to have a records with the same values for AA and BB? Are you interested in these rows or do you only care about rows with the same value of AA and different BB?
With a slight modification of a previous posting you can only select those rows that have distinct values of BB for the same value of AA
WITH t AS (
SELECT 'me' aa, 10 bb FROM dual
UNION ALL
SELECT 'me' aa, 20 bb FROM dual
UNION ALL
SELECT 'you' aa, 30 bb FROM dual
UNION ALL
SELECT 'you' aa, 30 bb FROM dual
SELECT DISTINCT aa, bb
FROM (SELECT aa, bb, COUNT(DISTINCT bb) OVER(PARTITION BY aa) cnt FROM t)
WHERE cnt > 1; -
Need Help w/ Programming (Feeling Physically Weak...a little)
I have not been able to compile my program since there is no compile option that I can choose at this time...& that I have not been able to download the appropiate components yet, but based on my program, I need to know if the program I have will excecute perfectly. This is based on the Split.java program & I am trying to extract words from article.txt. If there is an error in my program what needs to be typed & where is it shown within the program. Also, any symbols such as <>, -, etc. should not be included when article.txt is being redirected as an output.txt. I'm completely stumped & do not know where to go from here!
P.S. - At this time, I am still feeling a little dizzy after donating blood, so I really need help in this program. Don't worry, I'll be physically fine in a couple of hours! :)
- Split.java (actual program)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
public class Split
public static void main(String[] args)
throws IOException
BufferedReader console = new BufferedReader(
new InputStreamReader(System.in))
boolean done = false;
while (!done)
String inputLine= console.readLine();
if (inputLine == null)
done = true;
else
// break input lines into words
StringTokenizer tokenizer =
new StringTokenizer(inputLine);
while (tokenizer.hasMoreTokens())
// print each word
String word = tokenizer.nextToken();
System.out.println(word);
- Analyzer.java (my program)
CS46A Homework #5: Part 2
@author Mark P. De Guzman
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
public class Analyzer
public static void main(String[] args)
throws IOException
Statistician s = new Statistician();
BufferedReader console = new BufferedReader(
new FileReader(System.in));
boolean done = false;
while (!done)
String inputLine = console.readLine(firstLine);
if (inputLine == null)
done = true;
else
// break input lines into words
StringTokenizer tokenizer =
new StringTokenizer(inputLine);
while (tokenizer.hasMoreTokens())
// print each word
Char ch = word.CharAt(i)
if(character.isLetter(char);
Stat.nextWord();
- article.txt (document I need to extract the words from)
The desktop publishing <industry> is today a multi-million-dollar
business-much of it being conducted out of home offices by graphic
designers and {writers} who embraced desktop publishing early on as a
viable adjunct to their other skills. Although systems using Apple
"Macintosh" technology still dominate the high-end graphics market,
improvements in the Windows! operating environment have made
personal computers a viable component of many DTP systems as well!public class Analyzer
public static void main(String[] args)
throws IOException
THIS LINE IS WRONG:
Statistician s = new Statistician();
OBJECT NEVER USED - GET RID OF IT.
BufferedReader console = new BufferedReader(new FileReader(System.in));
boolean done = false;
while (!done)
THIS LINE IS WRONG:
String inputLine = console.readLine(firstLine);
firstLine IS NOT DEFINED
BufferedReader.readLine() DOES NOT ACCEPT ARGUMENT
if (inputLine == null)
done = true;
else
// break input lines into words
======
REWRITE YOUR READLINE FUNCTIONALITY LIKE THIS:
String inputLine;
while ((inputLine = console.readLine()) != null) {
======
StringTokenizer tokenizer = new StringTokenizer(inputLine);
while (tokenizer.hasMoreTokens()) {
// print each word
THIS LINE IS WRONG:
Char ch = word.CharAt(i)
Char SHOULD BE char
word IS NOT DEFINED - NEED TO INCLUDE "String word = tokenizer.nextToken()"
i IS NOT DEFINED - NEED TO CREATE A LOOP
THE LINE DOES NOT END WITH ";"
THIS LINE IS WRONG:
if(character.isLetter(char);
character SHOULD BE Character
char IS NOT DEFINED
MISSING ")"
THE LINE ENDS WITH ";"
WHAT DO YOU WANT TO DO IF IT IS A LETTER?
THIS LINE IS WRONG:
Stat.nextWord();
COMPLETELY MEANINGLESS - GET RID OF IT. -
I am trying to convert my prcess from DTS to SSIS. I am running this report out of SAP and then using Monarch to put into the correct form, then I am using the DTS to put it into the database on the SQL server. I am able to get all the other info to
move out having so much trouble here to get the plant number. The issuse is that it is on top on the page and it will change when a new plant is needed.
Thanks for any help
I need help wrting a script that will put that 7010 into a cloumn nnamed plant number.To convert from DTS packages to SSIS you can just open the DTS package in a new SSIS project (depends on target SSIS version by using SSDT or BIDS).
The rest is mechanics how the iteration with SAP is done and may be beyond the scope of this forum.
Arthur
MyBlog
Twitter -
Need help writing non-gui JMF program
I need to write a program that will convert a WAV file from a ULAW format to a GSM WAV file format. I first tried this with the Java Sound API and the WAV file format of GSM was not supported so I stumbled across JMF.
I can use the JMStudio and Export GUI programs that come with JMF to convert the wav file as needed. But now I'm trying to write a batch program (non-gui) to convert the file on the fly.
First, is this possible. Second, does anyone have any code samples of a batch java program using JMF in batch.
Thanks,
ScottNot exactly what I was looking for. After 2 days of beating my head against the wall this is what I got to work. Include the jmf.jar in my project. Here is my code.
import java.io.IOException;
import javax.media.DataSink;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.NoDataSourceException;
import javax.media.Processor;
import javax.media.control.TrackControl;
import javax.media.format.AudioFormat;
import javax.media.protocol.DataSource;
import javax.media.protocol.FileTypeDescriptor;
import jmapps.util.StateHelper;
public class TestAudio5 {
public static void main(String[] args) {
try {
Processor p = null;
StateHelper sh = null;
DataSource inSource = Manager.createDataSource(
new MediaLocator("file:c:\\ASSURANCE_THREE_MINUTE.wav"));
p = Manager.createProcessor(inSource);
sh = new StateHelper(p);
// Configure the processor
if (!sh.configure(10000)) {
System.out.println("can't configure");
System.exit(-1);
p.setContentDescriptor(new
FileTypeDescriptor(FileTypeDescriptor.WAVE));
//AudioFormat(java.lang.String encoding, double sampleRate, int sampleSizeInBits, int channels)
//AudioFormat(
// java.lang.String encoding,
// double sampleRate,
// int sampleSizeInBits,
// int channels,
// int endian,
// int signed,
// int frameSizeInBits,
// double frameRate,
// java.lang.Class dataType)
AudioFormat outputFormat = new javax.media.format.AudioFormat(
AudioFormat.GSM_MS,
8000.0,
0,
1,
0,
1,
520,
1625.0,
null);
System.out.println("outputFormat: " + outputFormat.toString());
TrackControl tc[] = p.getTrackControls();
for ( int i = 0; i < tc.length; i++ ) {
tc.setEnabled(true);
System.out.println("before format: " + tc[i].getFormat().toString());
tc[i].setFormat(outputFormat);
System.out.println("after format: " + tc[i].getFormat().toString());
if (!sh.realize(10000)) {
System.out.println("can't realize");
System.exit(-1);
// get the output of the processor
DataSource source = p.getDataOutput();
// create a File protocol MediaLocator with the location
// of the file to which bits are to be written
MediaLocator dest = new MediaLocator("file://c:\\test.wav");
// create a datasink to do the file writing & open the
// sink to make sure we can write to it.
DataSink filewriter = null;
filewriter = Manager.createDataSink(source, dest);
filewriter.open();
// now start the filewriter and processor
filewriter.start();
sh.playToEndOfMedia(5000);
sh.close();
filewriter.close();
} catch (NoDataSourceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("done!");
System.exit(-1); -
Need help writing Java program
I am a student conducting research as to the tolerance of users to a user interface. My idea is to take the existing tetris game but implement errors into it, so that on occasion the piece will not move in the direction you want it to. Also In the program there will need to be an introduction screen, 3 levels which end when you recieve a certain amount of points, a data table, for my use which collects information about time between moves, total time, par time( how long it would take if no errors occured), and levels completed. Also if a user fails to pass the level, at what point did they fail. The data will need to be organized in a logical order and finally there will need to be a way for me to retrieve the data. I already have the existing tetris code and I need to add to it, so if anyone could help me as I have no programming knowledge and I need this done as soon as possible, please contact me at [email protected] and I will be willing to pay for your time.
Thanks,
RossI am a student conducting research as to the
tolerance of users to a user interface. We call that Human Factors :-)
My idea is to
take the existing tetris game but implement errors
into it, so that on occasion the piece will not move
in the direction you want it to. So the idea is to piss the user off?!
Also In the program
there will need to be an introduction screen, 3
levels which end when you recieve a certain amount of
points, a data table, for my use which collects
information about time between moves, total time, par
time( how long it would take if no errors occured),
and levels completed. okay...
Also if a user fails to pass
the level, at what point did they fail. The data will
need to be organized in a logical order and finally
there will need to be a way for me to retrieve the
data. I already have the existing tetris code and I
need to add to it, so if anyone could help me as I
have no programming knowledge and I need this done as
soon as possible, please contact me at
[email protected] and I will be willing to
pay for your time.
Thanks,
RossFirst of all, it's probably not a good idea to post your email address, not that anyone will email you anyway. Second, I'm not sure how you're going to accomplish this programming task if you don't know how to program. See the problem? -
I need help writing a dive scoring program in C#, Help Please?
The state diving commission wants to computerize the scoring at its diving competitions. I have to write a program to automate the scoring of dives. Requirements:
After each dive, the user will be prompted to enter the:
diver's name;
diver's city;
degree of difficulty (ranges from 1.00 to 1.67); and
scores from five judges (scores can range from 0 to 10).
If an invalid score is entered, an error message will be displayed. The user will be prompted for the score repeatedly until a valid score is entered.
The program will then display the following information:
Diver's name
Diver's city
Dive final score: This is calculated by dropping the highest and lowest of the five judges' scores. The remaining three scores are added together, and the result is divided by 3 and then multiplied by the degree of difficulty.
The program will then prompt the user if she/he wants to process another dive. The user can type "Y" or "y" to continue, and "N" or "n" to quit.Hi,
The forum supports VS setup and installation. I think your issue is not about the forum.
Please clarify your project type. Is it webform or winform?
If it is webform, please post your issue to ASP.NET forum.
If it is winform, please post it to
winform forum.
Regards.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Need help writing a code for this program
Design a code that reads a sentence and prints each individual word on a different line
tsith's suggestion is excellent. Run it and see what happens. I just did that myself and doing so I learned something new about the Scanner class.
Before you run it, add a couple of extra System.out.println for (hopefully) illustrating debugging purposes:
import java.lang.String;
import java.util.Scanner;
public class Sentence {
// main line of program
public static void main(String[] args) {
boolean z;
String a;
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter sentence: ");
z = keyboard.hasNext();
while (z) {
System.out.println("z = " + z + ". Fetching the next word...");
a = keyboard.next();
System.out.println(a);
System.out.println("Done!");
}Let us know if the program ever prints "Done!" to the console. While you are waiting, read what the javadocs has to say about the Scanner class, and pay extra attention to what it says about the hasNext() and next() methods:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scanner.html -
I have recently taken it upon myself to learn Java, and I am having a few problems with a few programs. I am not understanding how to do certain things when writing the program. I am taking this class as an independent study, but we have a general guideline of programs that may help us prepare for the A.P. Exam. On of the programs that I am having difficulty with is a program designed to remove blanks. I have looked on the internet and found programs, but I need to write it in a certain way using arrays.
I am using BlueJ.
What I have so far is:
import java.util.ArrayList;
public class RemoveBlanks
String withblanks;
String removeblanks;
int num = 0;
ArrayList Array;
ArrayList Letter;
Letter = new ArrayList();
Array = new ArrayList();
EasyReader kboard = new EasyReader();
withblanks = "Take out these spaces";
//System.out.println("Input a sentence to remove the blanks in.");
//withblanks = kboard.readLine();
Array.add(withblanks);
for (num = 0; num < Array.size(); num++)
Letter[num] = Array.charAt(num);
if (Letter[num] == " ")
Array.add(removeblanks);
I honestly have no idea if this even makes sense. The book I am using is expecting that you already are familiar with the syntax and the language in general. I would appreciate it if someone could help guide me on how to do this the right way. Thanks in advance!In the future, post code between [co[i]de] tags. Some pointers:
1) You're confusing arrays and ArrayLists, they are two very different things.
2) All variable names should begin with lower case letters.
3) It is pointless to have two { in a row.
4) In order for a program to run, it needs a main() method.
5) Always compare Strings with the equals() method, not ==. -
Need help writing a Java rule in PDF Forms
I have created an invoice for my contractors via "forms", and in turn made each cell either a drop down list or "read only" field so they cannot change the rate of pay, etc. Here is my issue...My first drop down cell is titled "Job Description". When the contractor selects one of the 8 dropdown options within the Job Description field, I would like it to automatically fill in the hourly rate that is associated with that particular job description (or skill). I currently have my "rate" cell as a drop down, and I want to make that a read only, and when you select the A1 position from Job Description, it will populate the "rate" field with the appropriate amount for that A1 rate. I believe this can be done with writing some Java script, but I have never played with Java and I don't really have the time to teach myself. If anyone can help with me a quick tutorial, or even the formula I should use, so that I can just plug and play, that would be super helpful. If this is a time consuming issue, I would be interested in paying someone to do it for me. Thank you!
Hi George,
I was able to copy my data over to a fresh document, and now it works just fine....thank you so much for your insight and help!
I have another question if you have a moment.
I am trying to do a simple calculation of start time and end time for my employees. Do I need to do this via a javascript, and if so, what area in properties of the result field should I copy it to? for the purpose of the script, the fields are as follows:
DataField1 = start time
DataField2 = end time
DataField3 = total time
I would like to use the h:MM tt format for my time fields if possible.
I've attached a link to the file through my dropbox account, and you'll notice that I created three new fields at the top of the invoice just to test the time calculations before i mock up the whole document.
Dropbox - Contractor Invoice Template (1).pdf
Any help you can give me would awesome!
Thank you!!
Maybe you are looking for
-
Please help! Bizarre login/user account problem
In 24 years of using Macs, this is the most frustrating thing I've ever faced and I am in desperate need of help. For the entire story of my circumstances, see below. The short version of my problem: My auto-login user account is corrupt but I can't
-
Lost user profile and disk0s2: I/O error during start up in safe mode
My almost 2 year old Mac Book Pro (10.7.5) started lagging and rainbow spiraling last week and now it usually doesn't make it to the login page after boot up. It stays on the gray apple screen until I hold the power button to power it off. If it make
-
I have to attach a pdf which i get from spool and also attach some files
hi , i have requirement where i have to send a pdf as attachment , this pdf is generated throught the spool request , along with this pdf i need to attach some files from the presentation server, i am using the fm SO_OBJECT_SEND, but the problem is i
-
Cannot find new_domain in BPEL Process Manager
Hi Friends, I have upgraded the patch of oracle soa suite 10.1.3.1 to 10.1.3.4 ....I followed the procedure , i ran the scripts, installation was successful. but when i open my bpel process manager i dont find any change the GUI is not different...i
-
XI to XI - XI adapter communication
Hi I have the following scenario : BSysA --> XIA --> XIB --> BSysB XIA and XIB are my two integration servers with separate SLDs. Both XIA and XIB have been setup as integration servers in sxmb_admin My aim is to setup a communication between XIA