A preserved archive of the Logical Gamers community forums, 2009-2025. The original threads and posts, served read-only. Registration, posting and private messages are gone for good.

Help?

1.1k views · started by Taz ·
#1
Help?
Whats wrong with this please help me im about to lose my mind.

import java.util.Scanner; //Scanner Object.

/**
* @(#)DistanceTraveled.java
*
* DistanceTraveled application
*
* @author
* @version 1.00 2013/3/15
*/

public class DistanceTraveled {

public static void main(String[] args) {

//Declare Variables
int speed;
int hours;
int distance;



//Create a Scanner Object
Scanner keyboard = new Scanner(System.in);

//Accept user input
System.out.print("What is the speed of the vehicle?");
speed = keyboard.nextInt();

System.out.print("What is the hours it has traveled?");
hours = keyboard.nextInt();

distance = speed * hours;

//Display the table
System.out.println("Hours Distance Traveled");
System.out.println("-----------------------");
for (int houR = 1; Distance <= distance; Hour++ );
{

System.out.println(houR + "\t\t" + houR * distance);

}


}
}


Updated it.
#2
import java.util.Scanner; //Scanner Object.

/**
* @(#)DistanceTraveled.java
*
* DistanceTraveled application
*
* @author
* @version 1.00 2013/3/15
*/

public class DistanceTraveled {

public static void main(String[] args) {

//Declare Variables
int speed;
int hours;
int Hour;
double Distance = 0;


//Create a Scanner Object
Scanner kayboard = new Scanner(System.in);

//Accept user input
System.out.print("What is the speed of the vehicle?");
speed = kayboard.nextInt();

System.out.print("What is the hours it has traveled?");
hours = kayboard.nextInt();

Distance = speed * hours;

//Display the table
System.out.println("Hour Distance Traveled");
System.out.println("-----------------------");
for (Hour = 0; Hour<hours; Hour++){
System.out.println(Hour+1 + "\t\t" + Distance / (hours - Hour));
}

}
}
#3
Stapled wrote:
import java.util.Scanner; //Scanner Object.

/**
* @(#)DistanceTraveled.java
*
* DistanceTraveled application
*
* @author
* @version 1.00 2013/3/15
*/

public class DistanceTraveled {

public static void main(String[] args) {

//Declare Variables
int speed;
int hours;
int Hour;
double Distance = 0;


//Create a Scanner Object
Scanner kayboard = new Scanner(System.in);

//Accept user input
System.out.print("What is the speed of the vehicle?");
speed = kayboard.nextInt();

System.out.print("What is the hours it has traveled?");
hours = kayboard.nextInt();

Distance = speed * hours;

//Display the table
System.out.println("Hour Distance Traveled");
System.out.println("-----------------------");
for (Hour = 0; Hour<hours; Hour++){
System.out.println(Hour+1 + "\t\t" + Distance / (hours - Hour));
}

}
}


You are the best thank you.
#4
I have another problem which is making me explode...
Its so simple but so hard.

Write nested loops to draw this pattern:
##
#..#
#...#
#....#
#.....#
#.......#


Without the dots of course.
#5
Taz wrote:
I have another problem which is making me explode...
Its so simple but so hard.

Write nested loops to draw this pattern:
##
#..#
#...#
#....#
#.....#
#.......#


Without the dots of course.


What do you mean without the dots?

So is it supposed to be like

##
####
#####

etc?

Or with spaces instead of dots?
#6
for(int x = 0; x < 8; x++) {
if(x != 1 || x != 6) {
print("#")
for(int y = 0; y < x; y++) {
print(".");
}
print("#\n");
}
}


Wouldn't it be something like that? Just replace the "." for whatever you need to print there.
#7
Riddle wrote:
for(int x = 0; x < 8; x++) {
if(x != 1 || x != 6) {
print("#")
for(int y = 0; y < x; y++) {
print(".");
}
print("#\n");
}
}


Wouldn't it be something like that? Just replace the "." for whatever you need to print there.


Java uses "System.out.print" and "System.out.println" so it'd be

    	for(int x = 0; x < 8; x++) {
if(x != 1 || x != 6) {
System.out.print("#");
for(int y = 0; y < x; y++) {
System.out.print(".");
}
System.out.println("#");
}
}
#8
Stapled wrote:
Java uses "System.out.print" and "System.out.println" so it'd be

    	for(int x = 0; x < 8; x++) {
if(x != 1 || x != 6) {
System.out.print("#");
for(int y = 0; y < x; y++) {
System.out.print(".");
}
System.out.println("#");
}
}

It was just supposed to be pseudo code-ish. :P