Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 12 Online
OpenStudy (jaweria):

Anyone can help me with Java programming problems?

OpenStudy (espex):

You would be better served if you were to simply ask the question you need assistance with.

OpenStudy (jaweria):

alright thanks

OpenStudy (jaweria):

I do have couple of questions on java I tried to solve them but still giving me an error

OpenStudy (jaweria):

as you can see this question: Write a for loop that prints in ascending order all the positive integers less than 200 that are divisible by both 2 and 3, separated by spaces. I tried everything for this question and now I deleted all my wrong answers!! because I was angry.

OpenStudy (jaweria):

int i; for (i=0;i<200; i++) { if(i%2==0 i%3==0) { System.out.println [i]; } } This is what I had for an answer but still getting error

OpenStudy (opcode):

Try: ``` public class Main{ public static void main(String[] args) { for (int i = 1; i < 200; i++) { if ((i % 2) == 0 && (i % 3) == 0) { System.out.println(i); } } } } ```

OpenStudy (anonymous):

What Opcode is saying is that you're missing a few elements: The main function (which tells the JVM what to do) The && operator (logical and, returns true iff both booleans are true) between i % 2 == 0 and i % 3 == 0 (because supposedly you want the number to be divisible by 2 and 3) Replace [] with () when declaring function arguments. VALID: System.out.println("") INVALID: System.out.println[]

OpenStudy (anonymous):

daniel wats the difference between & and && in java

OpenStudy (anonymous):

The problem is actually a grouping problem. The statement: if ((i %2) == 0 && (i % 3) == 0) needs additional parenthesis to group the checks together. if ( ( (i%2) == 0) && ( (i%3) == 0)) This will make the program work.

OpenStudy (rsmith6559):

A single ampersand is a bit-wise and. A double ampersand ands boolean values.

OpenStudy (jaweria):

Anyone please help me get started with this problem in java its due tonight.

OpenStudy (jaweria):

Make a Java program that prints 3 lines and then uses one Turtle in one World to draw two digits or letters near the center. Learn to quickly write, save, test and improve programs outside of lab, and upload course work to Blackboard for credit, so this is not a problem.

OpenStudy (jaweria):

1. Code in the main method three calls to method System.out.println( ... ) print on 3 separate lines your full name, your UAlbany NetId and the "iClicker ID" from the back of your iClicker The code that prints the ID of one of my iClickers is System.out.println( "348F05BE" ); 2. Under the lines that commanded the printing, code additional lines to make a World, and then make a Turtle in that World. Here's how: World wRef = new World( ); Turtle tRef = new Turtle( w ); The two assignments coded by the two = symbols cause two variables wRef and tRef to hold, as their values, references to two new objects.  wRef is NOT a World; tRef is NOT a Turtle. wRef is the name of a reference variable; it's ok to say, for short, wRef is a variable. Similarly, tRef is the variable your program will use to refer to a Turtle for the purpose of telling it (or he or she) to move forward, turn and put its (his or her) pen up or down. These points will be stressed soon but not right away. For now, just base your work on my example. 3. Finish the program to make the Turtle draw, the first above the second, near the middle of Project 1 Introduction to Computer Science ICSI201 Spring 2013the window, the any two different digits or letters of your iClicker ID UNLESS THEY ARE B or E. If you have a B or an E or both, replace them with other digits or letters from your iClicker ID. The only Turtle methods you are allowed to use now are tRef.forward( integer distance ) tRef.turn( double amount of rotation ) tRef.penUp( ) tRef.penDown( ) and, optionally, setPenColor(... ) and/or setPenWidth( ... ). The moveTo( ... ) and other methods are ok in FUTURE ASSIGNENTS, but NOT Project 1, because moveTo makes the problem solving practice you get too easy! Important: How to figure out solutions to problems like this: 1. Study my sample code and its results: Trace using a pencil what the Turtle does (it mostly moves in a straight line or turns in place a given number of degrees) in order to draw the B and the E. 2. Write original code to draw your two digits or letters. 3. Finish, test, perfect and enjoy the first digit or letter BEFORE trying to work on the second. 4. Figure out, code, test, and IMPROVE your artistic results JUST A LITTLE AT A TIME, running the program and seeing the results again and again. It is OK to use trial, error and correction, which is what I did.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!