Don't have time to look up for these errors, but--anyways--I actually figured it out. Thanks, I suppose.
Type: Posts; User: javaBoi
Don't have time to look up for these errors, but--anyways--I actually figured it out. Thanks, I suppose.
Falling Distance
Time Distance
(seconds) (meters)
Exception in thread "main" java.util.IllegalFormatConversionException: f != java.lang.Integer
at...
2921
It prints out the string variables (which is fine), but then it gives me these compiler errors. Mind you, that's when I use the second line of code (which I currently have as a comment).
Okay, I'm getting somewhere now. Here's what I have
2919
And just need to get it to look like this:
2920
I know the whole printf method to align everything, but I can't seem to get this...
I was able to get the value of seconds to change (e.g. 1, 2, 3, 4, 5...10). How do I get the value to change for meters is the question I'm asking.
All I had to do was include "=" to if(fallingTime > 1).
Here's my updated Java code:
public class fallingDistance
{
public static void main(String[] args)
{
Here's the explanation of the problem:
PROBLEM:
OTHER STIPULATIONS (Made by Professor):
And this is the sample Display Output we're suppose to have:
#2, I want to know the other way of decimal fomatting. Still a bit confused by it.
Thanks for the reply.
I just typcasted the double into int (seems to work).
But, can you give me a sample of how your approach will work, too?
Okay, I was able to fix Issue #1.
Just had to add some padding to "%d".
Still can't figure out getting rid of the decimal places for the 80 and 120. I have "import java.text.DecimalFormat;" on...
Hi,
I'm having trouble formatting my output and issues with the decimal places. Here's my code:
import java.util.Scanner;
import java.text.DecimalFormat; // Imports DecimalFormat class for...
Yeah, the program works perfectly fine now.
Oh no, I needed the question in program (but not in the place I initially had it). Sorry for not being clear from the start.
It is, right? The program does ask for the service package first, then the number of hours used..Or is the program written in the wrong order in terms of execution of the statements?
public...
import java.util.Scanner;
public class internetPackage
{
public static void main(String[] args)
{
String input;
char servicePackage;
int hoursUsed, regularHours, extraHours;...
Nope, still gives me the same output, actually..
I wanted to do that, but how would I write it?
Would this work?
If (servicePackage != 'A' && servicePackage != 'a' && servicePackage != 'B' && servicePackage != 'b' && servicePackage != 'C' &&...
Oh, sorry. In my previous post, I actually mentioned that I took that "Invalid input. Hours cannot be negative." statement from it's original position and placed it as an ELSE statement for each...
Whoops, my bad. It's under "Default." Towards the end of the program.
For Switch Statements, "Default" acts like an "Else" incase the conditions being tested are all false, right?
...
Okay, I was able to resolve the "Invalid input. Hours cannot be negative" by placing if (hoursUsed < 0) System.out.println("Invalid input. Hours cannot be negative."); into each switch.
I'm still...
Hi everyone, first time entry. I have a problem with my java program output. It looks like the program logic is correct, but there are still some line of statements that are executed that I do not...