java code 8 of 1

java code 8 of 1

Develop a program that computes the distance a boat travels across a river, given the width of the river, the boat's speed perpendicular to the river, and the river's speed. Speed is distance/time, and the Pythagorean Theorem is c2 = a2 + b2.

View Answers

December 22, 2010 at 3:15 PM

Hi Friend,

Try the following code:

import java.util.*;
import java.text.*;

class DistanceTravelledbyBoat{

public static void main(String[] args){
DecimalFormat df = new DecimalFormat("##.00");
Scanner input=new Scanner(System.in);
System.out.print("Enter width of river: ");
double width=input.nextDouble();
System.out.print("Enter boat's speed perpendicular to river: ");
double boatspeed=input.nextDouble();
System.out.print("Enter river's speed: ");
double riverspeed=input.nextDouble();
double a=width;
double bs=boatspeed;
double c=0;
double t=a/bs;
double rs=riverspeed;
double b=t*rs;
double distance=c*c;
double BB=b*b;
double AA=a*a;
distance=AA+BB;
System.out.println("Distance boat travels: "+df.format(distance));
}
}

Thanks









Related Tutorials/Questions & Answers:
java code 8 of 1
java code 8 of 1  Develop a program that computes the distance a boat travels across a river, given the width of the river, the boat's speed perpendicular to the river, and the river's speed. Speed is distance/time
java code 1 of 2
java code 1 of 2  Create a washing machine class with methods as switchOn, acceptClothes, acceptDetergent, switchOff. acceptClothes accepts the noofClothes as argument & returns the noofClothes   Hi Friend, Visit
Advertisements
java code 1 of 2
java code 1 of 2  Create a washing machine class with methods as switchOn, acceptClothes, acceptDetergent, switchOff. acceptClothes accepts... the following code: import java.util.*; class WashingMachine { Scanner input
Filter collection in Java 8
Java in it. How to filter this using the Java 8? Thanks   Hi, Example of Filter collection in Java 8 You can use the following code in Java 8...Filter collection in Java 8  Hi, I have following collection
java program 8
java program 8  Develop the program calculateHeight, which computes the height that a rocket reaches in a given amount of time. If the rocket accelerates at a constant rate g, it reaches a speed of g ? t in t time units
8 - Java Beginners
8  Unit board is PIC18F4520 Purpose of euiqpment is to make test heart beat; fast/slow/moderate heartbeat I need to activate the speaker when testing for heartbeat. Should be able to start buzzing when testing is done. Should
Java 8 consumer class(interface) example
How to use the Java 8 consumer class(interface)? In this example program I will show you how you can use the consumer interface of the Java 8 to iterate.... The Consumer is a functional interface added to the Java 8 which is used to assign
Building and Running Java 8 Support
Building and Running Java 8 Support  As you know Java 8 is already released and available for download. Now I am developer of Java based projects. So... and run Java 8 application in Eclipse? Thanks   Hi, don't worry
JEE 8 - Java Enterprise Edition 8
JEE 8 - Java Enterprise Edition 8 Tutorials, Examples and latest updates... about the JEE 8:ADS_TO_REPLACE_1 The Java Community Process (JCP) team has started the development of next generation JEE 8 Java EE
Lambda Expression in Java 8
Lambda Expression in Java 8: Learn the power of Lambda Expression... in the Java 8. This is the biggest upgrade introduced in the Java so far... Expression in Java 8? The Lambda Expression is one of most important feature added
Learn the Java 8 and master the new features of JDK 8
JDK 8 - Java 8 Tutorial and examples: Learn JDK 8 with the help of examples..._TO_REPLACE_1 About Java 8 Java 8 Officially released JDK 8 Developers Preview Released Oracle to release Java 8 in March
task 1 - Java Beginners
task 1  Please write a Java client that send a small letters string to a Java server which convert it to uppercase letters and send it back..., Try the following code: import java.util.*; class ChangeCase{ public
Installing oracle Java 8 on Ubuntu 18.04
: Step 1: add java 8 repository with following command: sudo add-apt-repository ppa...Installing oracle Java 8 on Ubuntu 18.04  Hi, What are the steps for installing oracle java 8 on ubuntu 18.04? I want to install Oracle Java 8
problem 1 - Java Beginners
problem 1   Hi, please help me!!!! How can i code in java using Two-dimensional Arrays? This question is related to the one i posted before. this is my input data file: 88 90 94 102 111 122 134 75 77 80 86 94 103 113 80
java code7 of 1
java code7 of 1  Develop the program calculateHeight, which computes the height that a rocket reaches in a given amount of time. If the rocket accelerates at a constant rate g, it reaches a speed of g Ã?· t in t time units
java program 1
java program 1  (4) WAP to take input of a String and check wheather it is valid number or not? Sample Output1: Enter a String : 10 10 is a number Sample Output2: Enter a String : 10b1 10b1 is not a number (5) WAP to take
que 1 - Java Beginners
que 1  WAP to enter a sentence & count the no. of times a particular word occurs in it.Display the frequency of the searched word. eg- input...:frequency of word-2 times   Hi Friend, Try the following code: import
array 1 - Java Beginners
array 1  WAP to input values in 2 arrays and merge them to array M.  Hi Friend, Try the following code: import java.util.*; class MergeArray{ public static int[] merge(int [] ... arr) { int arrSize = 0
function 1 - Java Beginners
function 1  WAP to calculate the value of x,where x=tan(A)+tan(B)/1+tan(A)*tab(B)  Give more details like how to calculate and what is tan(A) and tan(B),etc
How to download and install Java 8 on Windows?
How to download and install Java 8 on Windows?  I am beginner in Java going to learn and make program in Java. Is there any tutorial for setting up Java development kit? Tell me How to download and install Java 8 on Windows
loop code to print the Pyramid: 1 1234 12 123 123 12 1234 1
loop code to print the Pyramid: 1 1234 12 123 123 12 1234 1  Hi, I want to know how the code to print the pyramid below works. It uses nested for loops. Pyramid: 1 1234 12 123 123 12 1234 1
Java programming 1 - Java Beginners
Java programming 1  write one program, which consists of a main...? There are nine words in total Java has a standard to index elements starting... be at position 1, etc ?A sentence is constructed with a series of words? Index 0 1 2 3 4
Java programming 1 - Java Beginners
Java programming 1  write one program, which consists of a main... 1 2 3 4 5 6 7 8 We need to provide a method...? There are nine words in total Java has a standard to index elements starting
About Java 8
Java 8 is slated to be released in March 2014 but the debate has already begun... for Java developers or not. This debate has made Java 8 update as the most..., streams, functional interfaces and others. Some of the features Java 8 might have
Java EE 8 Takes Off
Finally its good news for Java developers as Java EE 8 Takes Off The future version of Java EE 8 officially launched as JSR 366 via the JCP (Java Community... to be introduced in the JEE8. The primary focus of Java EE 8 will be providing
Java programming 1 - Java Beginners
Java programming 1  hi there, Sir! Can u help me check where my program gone wrong? here are my coding =D, hope to get reply from u guys soon... = JOptionPane.showInputDialog(null,"Enter mark 1", "Homework 8",JOptionPane.QUESTION_MESSAGE
java bits 8 - Java Interview Questions
java bits 8  Assume that country is set for each class. Given: 10. public class Money { 11. private String country, name; 12. public getCountry() { return country; } 13.} and: 24. class Yen extends Money { 25. public
Java programming 1 - Java Beginners
Java programming 1  Thx sir for reply me ^^ err how bout if using scanner class or further method to solve that code? instead of using array?  ...://www.roseindia.net/java/java-tips/examples-introductory/console/console-input
Java programming 1 - Java Beginners
Java programming 1  Hi sir, i facing problem in this program....   Hi friend, Please send me full code. Because your.../java/example/java/swing/ Thanks
Java EE 8 Takes Off
Java EE 8 the next generation application development platform is starting... of next generation enterprise application development platform Java EE 8. JCP team is no featuring out the features to be added to the Java EE 8
Java programming 1 - Java Beginners
Java programming 1  thx sir for reply me..but sir can u pls simplify...; Hi friend, 1. Ask the user for their height. Convert it to a double... is the code. import javax.swing.JFrame; class BMI { public static void
Java 8: Java 8 is officially released and it can be downloaded
Java 8 officially released Java 8 is finally available for download - Download the latest Java 8 SDK and start developing next generation applications for your client. Java 8 comes with many new features including Lambda expression
EXCEPTIONS-----1 - Java Interview Questions
EXCEPTIONS-----1  How To Handle The Exceptions With Out Using Try,Catch And Throws?I Want Region Plz Post Answer
INTTERFACE 1 - Java Interview Questions
INTTERFACE 1  What is a Interface?  Hi Friend, Interface is the collection of methods with empty implementations and constants variables ( variables with static and final declarations ). All the methods
Can u print in turbo c 9 8 7 6 5 4 3 2 1 0 using pre increment operator Only use print ++a in the same printf() command ten times)
Can u print in turbo c 9 8 7 6 5 4 3 2 1 0 using pre increment operator Only use print ++a in the same printf() command ten times)  Can u print in turbo c 9 8 7 6 5 4 3 2 1 0 using pre increment operator Only use print
Maven dependency for com.cedarsoft - open version 8 is released. Learn to use open version 8 in Maven based Java projects
- open version 8 ) in their Java project if it is based on Maven and Gradle. How...; com.cedarsoft - open version 8 in Java projects. Follow the step by step tutorial... and includes  com.cedarsoft - open version 8 java library in your project
Maven dependency for com.projectdarkstar - sgs version 8 is released. Learn to use sgs version 8 in Maven based Java projects
this version ( com.projectdarkstar - sgs version 8 ) in their Java project if it is based... in project? Steps to use  com.projectdarkstar - sgs version 8 in Java... and includes  com.projectdarkstar - sgs version 8 java library in your
Can u print in turbo c 9 8 7 6 5 4 3 2 1 0 using pre increment operator Only use print ++a in the same printf() command ten times)
Can u print in turbo C  Can u print in turbo c 9 8 7 6 5 4 3 2 1 0 using pre increment operator Only use print ++a in the same printf() command ten times
how to read text file with java 8 stream api
code. how to read text file with java 8 stream api? Thanks   Hi...how to read text file with java 8 stream api  Hi, I want to use Java... in Java 8. package my.code; import java.io.IOException; import
Java 8 Consumer Interface with forEach Loop
How to use the Java 8 Consumer Interface with forEach Loop? In this tutorial I will explain you about the Java 8 Consumer Interface and then explain you how... you can use the Java 8 Consumer Interface and then iterate through the class
Read file line by line in Java 8
Java 8 Read file - Reading file line by line in Java 8 Today  we will discuss the new API which is added to Java 8 for reading a file line by line... feature of Java 8. In Java 8 the class java.nio.file.Files was modified and new
Maven dependency for com.aspectran - aspectran-parent version 8 is released. Learn to use aspectran-parent version 8 in Maven based Java projects
use this version ( com.aspectran - aspectran-parent version 8 ) in their Java...-parent version 8 in Java projects. Follow the step by step tutorial for using...;version>8</version> </dependency> Above code is the maven
Maven dependency for com.adeptj - adeptj-parent version 8 is released. Learn to use adeptj-parent version 8 in Maven based Java projects
( com.adeptj - adeptj-parent version 8 ) in their Java project if it is based... in project? Steps to use  com.adeptj - adeptj-parent version 8 in Java projects...;/artifactId> <version>8</version> </dependency> Above code
Maven dependency for com.blazebit - blazebit-parent version 8 is released. Learn to use blazebit-parent version 8 in Maven based Java projects
this version ( com.blazebit - blazebit-parent version 8 ) in their Java project... version 8 in Java projects. Follow the step by step tutorial for using the latest... that downloads and includes  com.blazebit - blazebit-parent version 8 java library
Maven dependency for de.alpharogroup - silly-collections version 8 is released. Learn to use silly-collections version 8 in Maven based Java projects
; de.alpharogroup - silly-collections version 8 in Java projects. Follow the step by step...; de.alpharogroup - silly-collections version 8 java library in your project. ADS...-collections', version: '8' Above code will enable the Gradle to down
Maven dependency for org.apache.maven.plugins - maven-plugins version 8 is released. Learn to use maven-plugins version 8 in Maven based Java projects
-plugins version 8 ) in their Java project if it is based on Maven and Gradle. How...? Steps to use  org.apache.maven.plugins - maven-plugins version 8 in Java...;version>8</version> </dependency> Above code is the maven
Maven dependency for com.cathive - oss-parent version 8 is released. Learn to use oss-parent version 8 in Maven based Java projects
( com.cathive - oss-parent version 8 ) in their Java project if it is based on Maven...? Steps to use  com.cathive - oss-parent version 8 in Java projects. Follow...; <version>8</version> </dependency> Above code is the maven
Maven dependency for org.jboss - jboss-parent version 8 is released. Learn to use jboss-parent version 8 in Maven based Java projects
( org.jboss - jboss-parent version 8 ) in their Java project if it is based... in project? Steps to use  org.jboss - jboss-parent version 8 in Java projects...; org.jboss - jboss-parent version 8 java library in your project. ADS
Maven dependency for org.openjfx - javafx version 13-ea+8 is released. Learn to use javafx version 13-ea+8 in Maven based Java projects
( org.openjfx - javafx version 13-ea+8 ) in their Java project if it is based... in project? Steps to use  org.openjfx - javafx version 13-ea+8 in Java... and includes  org.openjfx - javafx version 13-ea+8 java library in your project
How to Install Oracle Java JDK 8 in Ubuntu 16.04?
to install Oracle Java 8: Step 1: add java 8 repository with following command: sudo...How to Install Oracle Java JDK 8 in Ubuntu 16.04?  Hi, Let's know the commands to install Oracle Java 8 on Ubuntu 16.04. How I can install Oracle

Ads