Write A Program That Display Miles And Kilo
Apr 21, 2014
1. Write a program that displays the following table (note that 1 mile is 1.609 kilometer):
Miles Kilometers
1 1.609
2 3.218
3 4.827
...
...
9 14.481
10 16.090
Note: use for loop and printf() to format your output
public class MilesandKilometers {
public static void main(String[] args) {
System.out.println("Miles Kilometers");
int miles = 1
;
for (int i = 1; i <= 10; miles++, i++) {
System.out.println(miles + " " + miles * 1.609);
}
}
}
how to make it like the instruction said " use for loop and printf() to format your output".
View Replies
ADVERTISEMENT
Oct 14, 2014
Write a program that reads an integer and displays, using asterisks, a filled diamond of the given side length. For example, if the side length is 4 the program should display.
*
***
*****
*******
*****
***
*
I have it where it displays the top half of the diamond. But i cannot figure out how to get it to draw the bottom half.
import java.util.*;
public class E616 {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.print("Enter number of rows. ");
int N=input.nextInt();
[code]...
View Replies
View Related
Feb 15, 2015
I want to write a java program which displays to get the GPA of a student as a keyboard input. Then display the class of the degree according to the following criteria using a switch-case statement (if-else statements cannot be used). If the user insert an invalid gpa you should display a message Invalid GPA.
gpa ≥ 3.50 First Class Hons
3.49 ≥ gpa ≥ 3.00 Upper Second Class Hons
2.99 ≥ gpa ≥ 2.50 Lower Second Class Hons
2.49 ≥ gpa ≥ 2.00 Pass
2.00 ≥ gpa Fail
Here is my code:
import java.io.*;
public class q7
{
public static void main(String[] args)
{
InputStreamReader ISR=new InputStreamReader(System.in);
BufferedReader BR=new BufferedReader(ISR);
[code]...
.But when I use Command console to run this it says: 1111.jpg. I also wanna know is there another way to do this with switch- case statements.
View Replies
View Related
Jan 23, 2015
I have to write a program the calculates the MPG and display's the result on the screen. However, I have three errors I just can't seem to figure out. jGrasp points to the following error, but doesn't tell me what it is:
Programming Challenge #9.java:34: error: cannot find symbol
gallons = keyboard.nextInt();
^
symbol: variable keyboard
location: class MPG
3 errors
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
My code is as follows:
import java.util.Scanner;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
// This program has variable of several of the integer types.
public class MPG {
public static void main(String[] args) {
[Code] ....
View Replies
View Related
Jul 22, 2007
I'm going to be taking an object oriented paradigm using java during intersession in a few months. I'm trying to brush up on it a bit. The problem is. Write an application that displays the numbers 1 to 4 on the same line, with each pair of adjacent numbers separated by one space. Write the program using the following techniques:Use one system.out.printLn statement.Use four system.out.print statement.Use one system.out.printf statement.
This is what i have so far .
Java Code: public class Display
{
public static void main(String [] args) {
System.out.print("1 ");
System.out.print("2 ");
System.out.print("3 ");
System.out.print("4 ");
System.out.println(" ");<----is that what that is supposed to look like, and where it goes?
System.out.printf(" %s %s %s %s ");????
}
} mh_sh_highlight_all('java');
i cant test this my console isn't working right, and i haven't finished my compiler install.
View Replies
View Related
Nov 28, 2014
I'm doing to create miles/kilometers converter. If I put the mile, converting to kilometer is right. However, if I put the kilometer, converting to mile comes out wrong value. Which part is wrong?
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
[Code] .....
View Replies
View Related
Sep 19, 2014
Pretty much what im trying to accomplish, i need to write a program that figures out the distance between one point to another, using miles and feet..
Heres how it has to look: "The distance from my uncles house is ___ miles, or ____ feet."
I can get it to run if i add only whole miles..but when i try to add 8.5 miles, and compile, the program flips out..I know i need to use a double somewhere, but cant figure it out, here is my code..
import java.util.Scanner; //required for input
public class feetToMiles {
public static void main (String[] args){
//Create new scanner object called input
Scanner input = new Scanner (System.in); //allows for input
[Code] ....
View Replies
View Related
Jun 25, 2014
ABC is a company that designs and prints personal business cards. The company has asked you to write a Java application to display the layout of the information in a typical business card order. Data items in a typical business card include the customer's name, address, city, state, postcode, home phone number, and work phone number.
Write, compile, and test a Java class that displays these data items in a command window. Alternatively, you could also create it using a dialog box. Please include appropriate comments in your class.
Please named your class BusinessCard(LIM).java. (eq. BusinessCardLIM.java)
View Replies
View Related
Sep 21, 2014
I have a program where the user enters in the miles and then it is supposed to get multiplied by feet but I keep getting this error.
GetUserInfo.java:12: error: bad operand types for binary operator '*'
int total = name * feet;
^
first type: String
second type: int
1 error
This is my code so far :
import java.util.Scanner;
public class GetUserInfo
{
public static void main(String[] args) {
String name;
int miles;
[Code] ....
View Replies
View Related
Mar 26, 2014
I want to write a Utility to calculate the shipping charges based on the product weight in pounds and distance in miles. How we can go about it.
View Replies
View Related
Jul 21, 2014
How do i write a program using textEdit? I can't even get the examples to open?
View Replies
View Related
Mar 19, 2014
My program successfully reads a file, reports back what it finds and creates an output file. However, I cannot get it to write to the output file, it is always blank!
Here's my code:
import java.util.Scanner;
import java.io.*;
public class Ex19
{
public static void main (String [] args)
{
//Variables
[code]....
View Replies
View Related
Jan 23, 2015
I have to write a program that find the sum of two numbers 62 and 99 and stores them in a variable named total. However, I have one error that I just can't get rid of and can't tell what it is. I'm using jGrasp and here's what it says:
Programming Challenge #5.java:14: error: class SumofTwoNumbs is public, should be declared in a file named SumofTwoNumbs.java
public class SumofTwoNumbs {
^
1 error
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
and here: is my code:
import java.util.Scanner;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
// This program has variable of several of the integer types.
public class SumofTwoNumbs {
public static void main(String[] args) {
[code]....
View Replies
View Related
Nov 24, 2014
Write a program called GeometricMean that prompts the user to
1.Enter the number of values (total number of instances) that should be processed
2.A set of values to be processed (in a while loop)and then calculate the geometric mean of the values entered. You should use a while loop to perform the multiplication part of the calculating the geometric mean. The program should output the initial data and the labeled geometric mean. Consider printf, and DecimalFormat.
My Program:
import java.util.Scanner;
public class GeometricMean{
public static void main(String[] args) {
Scanner keyboard= new Scanner(System.in);
[code]...
View Replies
View Related
Apr 9, 2014
Write a java program that uses a While loop and persistent output to count down from 33 to 0 by threes, and put each value on a separate line, also do this in for loop.
View Replies
View Related
Feb 24, 2015
How to Write Program with out using control structures
IMG_4216.JPG
View Replies
View Related
Dec 10, 2014
I'm trying to use graphics for my programs and here I'm trying to write a program that searches through files for text received from a JTextField. However, it does not seem to be working as my message is not displayed when text is found...
I used applet. Here are the functions:
JTextField jtf;
JFrame jf;
public void init()
[Code].....
View Replies
View Related
Oct 17, 2014
I'm rather new to programming and I'm trying to make a gui program that will allow the user to create text files. They will be prompted to enter what they'd like to save their file as and then they will be allowed to input text to that file . They will also be allowed to open their files to modify or view its contents. So to start things off, I'm making a prototype if you will.. I've been able to save to a file the problem occurs when I try to read/display it.
Main Class:
public class MainActivity {
public static void main(String[] args) {
// Access to other classes
WriteFile writer = new WriteFile();
ReadFile reader = new ReadFile();
[Code] ....
View Replies
View Related
Jan 12, 2015
I have a question. How to write a progamme which compensates an average if it is less than a 10/20. I use eclipse and database HSQLDB. I have a table with notes. After the compensates, I must change the note in my database.
I have three notes
12, 11, 5
The average is 12+11+5/3=9,33
I take the lowest note: 5
12+11+x/3 = 10
12+11+x/3 = 30/3
x=30-23
x=7
The new average is 12+11+7/3=10
View Replies
View Related
Dec 31, 2014
My code:
public class Fibonacci {
/**
* @param args
*/
public static void main(String[] args) {
int f[]=new int[100];
for(int j=0; j<100;j++){
f[j]=j;
[Code] ....
How can I improve my code?
View Replies
View Related
Apr 15, 2014
As per requirement i need a dynamic multi map in my application. How to write a method to create the dynamically map.
View Replies
View Related
Mar 4, 2015
Write a program named QuadraticTable.java that takes three double arguments and two int arguments (in that order) from the command line. The three doubles will represent a, b, and c from the quadratic formula.
If the discriminant is non-negative, find and print the solutions to the quadratic equation. (The plus/minus sign in the quadratic formula indicates that you would separately perform both operations). Otherwise print "no real solutions".
Then using the last two int arguments as x_min and x_max, print a table of x and ax
2 + bx + c
values using the a, b, and c read in as command line arguments.
Sample output: (command line arguments were 1 0 2 -3 3)
1x^2 + 0x + 2 has no real solutions.
X 1x^2 + 0x + 2
-3 11
-2 6
-1 2
0 2
1 3
2 6
3 11
View Replies
View Related
Jul 8, 2014
I am trying to write a program that takes two numbers and multiplies them. I got this idea from this running conversion program
import java.util.Scanner;
public class Convert
{
public static void main (String [] args)
{
Scanner reader = new Scanner (System.in);
double farenheit;
double celsius;
[code]...
i am getting a cant find symbol for the output = (alpha*beta) line..Also, am I using the reader object correctly ? hould I create two reader objects as there are 2 inputs needed?
View Replies
View Related
Oct 5, 2014
having some trouble doing this. Here are the requirements:
1)Write a program using loop and break to calculate the value of PI.
2)You can use the following equation to calculate PI. PI=4/1-4/3+4/5-4/7+4/9-4/11+4/13 etc.. The program shouldn't loop until the criteria is satisfied.
3)The criteria is the value of PI you get is very close to the “real” value (3.1415926), meaning that their difference
should be smaller than a very small numeric number, e.g., 0.0001).
4)The control structures you may need for this program are loop, if-else, and unlabeled break.
5)The output should have the format: for each iteration, it has iteration number and the corresponding value of PI until that
iteration. The last line would be the final value of PI.
Here is my code so far:
package ids;
public class IDS {
public static void main(String[] args) {
double pi = 0;
for(int i=1; i<=100000; i++){
if ((i%2)==0){
pi+=(4/(2*i-1));
[code]...
View Replies
View Related
Feb 21, 2015
Design, write a java program to input 7 integers and, for each integer, calculate and display its square and cube.
View Replies
View Related
Mar 2, 2014
I want an app that I can use to save the name, address, item sold, subject discussed and date that I visited someone - in a job similar to a sales rep. I would like to be able to choose how to sort the info so that if I sort by date I can see who hasn't been visited for the longest and start there. If I think of someone's name then of course I want to sort by name.
One of my friends says he works with "php"[? I'm still learning these terms] and everything happens online. I would like it to be an android app so it can be done without an internet connection ....
View Replies
View Related