OK here is the deal...ive looked and looked at my java book...i am in oracle 2 this year this will be my 1st year...i am doing allright in it...as long as the book can help me...but see i cant find these answers...i have found 1, 2, 3
but not the rest witch is 4, 5, 6, 7,8,9,10...i kno that seems alot...but if some one could explain to me how to do them i could probly do better but i dont kno wat to do....here are the for loops
4.Write a program that prints out the multiples of 4 from 12 to 48 across the page with spaces in between the numbers
5.write a program that prints out the sum of the numbers from 1 to 100
6.write a program that prints out the sum of the multiples of 6 from 36 to 300
7.write a program that prints out the product of numbers from 5 to 11
8.write a program that prints out the factorial of a number that is typed in
9. write a program that prints out the sum of the even numbers from 12 to 28
10. write a program that prints out the product of the odd numbers for 1to 13

Ok i kno thats alot and i am really sorry i been looking for the answers in my book for about 4 days now and i cant find these answers if some would could show me how to do these then i think i could get them....PLEASE SOME ONE HELP ME I AM BEGGING YOU! :sad:

Dani AI

Generated

— you can solve every one of these by following a simple pattern: (1) do the sequence on paper to see the start, end and step; (2) decide whether you need to print each value or accumulate (sum/product); (3) write a for-loop using those bounds. As suggested, doing the math by hand first makes the loop obvious.

A few compact Java patterns you can reuse:

Print a stepped sequence (replace START, END, STEP):

for (int i = START; i <= END; i += STEP) {
    System.out.print(i + " ");
}
System.out.println();

Sum values in a range with a step:

int sum = 0;
for (int i = START; i <= END; i += STEP) {
    sum += i;
}
System.out.println(sum);

Product of values (small ranges — use long or BigInteger for big products):

long product = 1L;
for (int i = START; i <= END; i += STEP) {
    product *= i;
}
System.out.println(product);

Factorials and very large products: use BigInteger to avoid overflow.

import java.math.BigInteger;
import java.util.Scanner;

Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
BigInteger fact = BigInteger.ONE;
for (int i = 1; i <= n; i++) {
    fact = fact.multiply(BigInteger.valueOf(i));
}
System.out.println(fact);

Quick tips: use i += 2 to iterate only evens or odds (or start at the first even/odd). To get the first multiple of n inside a range, compute first = ((start + n - 1) / n) * n. Initialize sums to 0 and products to 1. Watch overflow: long reliably holds up to 20!; beyond that switch to BigInteger. When stuck, print intermediate i and the accumulator to find off-by-one errors.

have you ever taken any course in highschool mathematics (most of the stuff you're asking is primary school math even)?

If not start there. If yes practice what they taught you.

If you can't see the code in your head, do the calculations on paper and determine an algorithm from that.

Someone writing the code for you (and most of these are one or two lines so giving you any code without writing it all becomes rather difficult) won't help you at all in the end as you learn exactly nothing at all.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.