Biscuit Tickler's Profile
Reputation: 0
Apprentice
- Group:
- New Members
- Active Posts:
- 13 (0.06 per day)
- Joined:
- 01-October 12
- Profile Views:
- 136
- Last Active:
Oct 20 2012 06:56 PM- Currently:
- Offline
Previous Fields
- Country:
- US
- OS Preference:
- Windows
- Favorite Browser:
- Chrome
- Favorite Processor:
- Intel
- Favorite Gaming Platform:
- PC
- Your Car:
- Honda
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: Printing out numbers that were looped.
Posted 6 Oct 2012
I had a friend help me. I had to use a string that held all of the numbers in the loop. Here is the code.
import java.io.*; import java.util.*; public class SummingNumbers { public static void main (String[] args) { int totalValue = 0; double totalNum = 0; String temp = ""; //was forced to use strings because I couldn't think of any other way to do this program. Scanner value = new Scanner(System.in); System.out.print("Enter starting value: "); int x = value.nextInt(); System.out.print("Enter ending value: "); int y = value.nextInt(); System.out.println(" "); for (int i = x; i<=y; i++) //renames x because x is already defined. { temp +=i + ","; //formats the looped number to have a comma beside of it when calculating the sum below. System.out.println(i); totalValue += i; totalNum ++; } System.out.println("The sum of " + temp + " is " + totalValue); double answer = totalValue/totalNum; System.out.println("The average of " + temp + " is " + answer); } } -
In Topic: New to Java: Trying to truncate a double from 15 decimal places to 2
Posted 5 Oct 2012
The users above me are correct but I use Math.round(); I guess I just find it easier because I have used it so much. For example:
double x = 14.23424242; double newx = Math.round(x*100.0)/100.0;
-
In Topic: Printing out numbers that were looped.
Posted 5 Oct 2012
Kinaces, on 05 October 2012 - 08:29 PM, said:You do not actually want to use x in your for loop.
Since x is your min value you don't want to change it. In your for loop you are increasing x.
Anytime you want to print the numbers from x to y just create a loop.
Create a new int (EX: int i = x) in the for loop declaration and set is to x. Loop until Y. Then print out that variable in the for loop.
Now for the reason your for loop is working is because the first thing you set in a for loop is if you want to create a variable specifically for the for loop. Since you are using a pre-existing variable you do not have to have that first declaration.
Ok, I fixed the for loop and now I need to figure out how to print the numbers that were looped. -
In Topic: Buying a portable HDD
Posted 5 Oct 2012
I'm not really knowledgeable about this subject but I would go with the one with the most features in your price range along with the amount of reviews it has and if they say good or bad things about it. -
In Topic: New to Java and Loops.
Posted 2 Oct 2012
I can't find the edit button(if there is one) so I'll just make a new post. I figured the problem out and now the Run # increases by 1. Is there any way I can stop over thinking these?
My Information
- Member Title:
- New D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
-
Contact Information
- E-mail:
- Click here to e-mail me
Friends
Biscuit Tickler hasn't added any friends yet.
|
|


Find Topics
Find Posts
View Reputation Given
|
Comments
Biscuit Tickler has no profile comments yet. Why not say hello?