Request A User To Input Two Numbers For Num1 And Num2 And Do Arithmetic?

Feb 6, 2014

New to programming, and my teacher wants us to declare two variables : num1 and num2, and have the user input values, then run it through 2*num1 - num2.

Here is what I have so far, and I am lost and frustrated:

package hellowworld;
import java.util.Scanner;
public class definevariables {
static Scanner console = new Scanner(System.in);
public static void main(String[] args) {
int num1;
int num2;

[Code] ....

View Replies


ADVERTISEMENT

Program For Class To Request User Input For Base Salary

Feb 24, 2014

I had to write a program for class to request user input for base salary, number of years worked, and total sales. Then use the data to find out the employee's paycheck when including a bonus. I have a few issues with the code, as I have one bug, then it won't calculate anything. what I'm missing?

package chapterone;
import java.util.Scanner;
public class Examplelab {
static Scanner console = new Scanner(System.in);
public static void main(String[] args){
double baseSalary;
double noOfServiceYears;
double totalSales;

[Code]....

View Replies View Related

Program That Takes User Odd Number And Print Prime Numbers Lower Than User Input

Nov 4, 2014

I have been struggling with this program for weeks. This program is supposed to take a user's inputted odd number and then print out all prime numbers lower than that number.

public class PrimeNumber
{
Scanner scan = new Scanner(System.in);
int userNum;
String neg;

public void getUserNum()

[code]...

View Replies View Related

Reversing Numbers (User Input)

Dec 11, 2014

I am writing a program to reverse a user inputted number (Example - 54321 is 12345) The code works great minus the fact that if I input a number that begins with zero, the output will drop the zero. Would it make more sense to just set this up using strings?

import java.util.*;
public class Week7_Programming_Problem
{
static Scanner console = new Scanner(System.in);
public static void main(String[] args)
{
int inputNum, outputNum;

[Code] ....

View Replies View Related

1D Arrays List Of Numbers From User Input?

Dec 4, 2014

Write a program to maintain a list of the high scores obtained in a game. The program should first ask the user how many scores they want to maintain and then repeatedly accept new scores from the user and should add the score to the list of high scores (in the appropriate position) if it is higher than any of the existing high scores. You must include the following functions:

-initialiseHighScores () which sets all high scores to zero.

-printHighScores() which prints the high scores in the format: “The high scores are 345, 300, 234”, for all exisiting high scores in the list (remember that sometimes it won’t be full).

-higherThan() which takes the high scores and a new score and returns whether the passed score is higher than any of those in the high score list.

-insertScore() which takes the current high score list and a new score and updates it by inserting the new score at the appropriate position in the list

View Replies View Related

Add All Even Numbers Between 2 And User Input Number Which Is Included In Addition?

Apr 17, 2014

import java.util.*;
 public class SumOfAllEvens { 
public static void main (String[] args) { 
Scanner s = new Scanner (System.in);
 //for (int i=1; i<4; i++){
int usernumber;

[code]....

I'm supposed to use a for loop that runs until it reaches the number input by the user, but I'm not sure how to tell the program to add the user's number along with all of the even numbers in between the user input and 2.

View Replies View Related

User To Input 10 Numbers - Find Smallest Element In Array

Dec 2, 2014

I am trying to write a code that asks the user to input ten numbers and then finds and displays the smallest number out of the ones given. I am supposed to implement arrays into the program to do this. But the problem I have run into is that when I compile the code in jgrasp, I am given several error messages and I am not quite sure what I have done wrong. I'm assuming it is either a syntax or a logical error on my part but reading over the code I do not understand what is causing these errors.

This is the most current draft of my code:

import java.util.Scanner;
 public class Exercise7_9 {
public static void main(String[] args) {
double[] numbers = new double[10];
//Enter ten double numbers: Scanner(System.in)
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.println("Please enter ten numbers: ");

[Code] .... 
 
/* Sample Run:
Enter ten numbers: 1.9, 2.5, 3.7, 2, 1.5, 6, 3, 4, 5, 2
*/

And these are the exact error messages:

----jGRASP exec: javac -g Exercise7_9.java
Exercise7_9.java:35: error: '.class' expected
if (double m > list[i]) {
^
Exercise7_9.java:35: error: illegal start of expression
if (double m > list[i]) {

[Code] .....

View Replies View Related

Find Arithmetic Mean Of The Numbers Stored In Array

Feb 23, 2014

The program below is intended to find the arithmetic mean of the numbers stored in the array q in two ways: once by storing the numbers in an ArrayList d, where you allow all the necessary conversions to be performed automatically; and once by storing them in an ArrayList e, where you perform all the conversions by hand. Complete the program.

Here is what I have so far:

double[] q = { 0.5, 2.4, 7.4, 2.8, -6.2 };
ArrayList<Double> d = new ArrayList<Double>();
ArrayList<Double> e = new ArrayList<Double>();
for ( double x : q ) {
d.add( x );
e.add ( new Double ( x ) );

[Code] .....

Why does it still show "a / d.size?" I thought I fixed that. Whatever, it's supposed to be "dTotal / d.size()", etc.

View Replies View Related

User Input Random Numbers Then Program Sort Them In Different Ways - Missing Return Statement

Apr 7, 2014

I have been assigned to write a program that has a user input random numbers then the program is to sort them in different ways. I have the coding for the different sorts but, I have an error saying that I am missing a return statement in the "Bubble" method. I am trying to return "arr[i]" in the "for loop" which gives me this error, and when I try to take the "return arr[i]" outside of the "for()" loop the error reads the it cannot locate variable "i".

import java.awt.* ;
import java.awt.event.*;
import javax.swing.*;
public class SwingSorts extends JFrame implements ActionListener
{
JRadioButton bubble;
JRadioButton selection;

[Code] .....

View Replies View Related

User To Enter 10 Numbers And At The End Prints Out Distinct And Non-repeated Numbers

Nov 23, 2014

I have to make a program that prompts the user to enter 10 numbers and at the end it prints out the distinct numbers and then the other numbers that weren't repeated...

I have the part where it prints out the distinct numbers but I stuck on how to make it print out the other numbers that didn't repeat...

import javax.swing.JOptionPane;
public class DistinctNumbers {
public static void main(String[] args) { 
String getInput;
int input;
int[] numbers = new int[10];

[Code] ....

View Replies View Related

Servlets :: Delivery Of SMS Containing National Identification Number Of User Upon Request

Mar 6, 2015

I have a project which consists of the delivery of an sms containing the national identification number of a user upon request. This request will be in the form of an sms. Say for instance a client sends an sms to the mobile operator, my app would retrieve the national id and communicates it to the mobile operator which would send it the client.

I have downloaded and installed kannel as well the smsc simulator SMPPSim and also gone through some of the documentation. Now my problem is, how can i simulate the reception of an sms? Say for instance a client sends 'nidn 5', i want to be able to take 5 and process it in a servlet to retrieve the associated national identification number. How to achieve this.

View Replies View Related

How To Print PDF In Java - Send Document To Printer Upon User Request

Apr 24, 2008

I've been googling information on how to print a pdf in java, and it seems that the java print api is used more for printing from a swing app. What I'm needing to do is send a pdf document to the printer upon user request. I would like my app to work as follows - User selects pdf to be printed- Program determines pages to be printed and deducts amount from user account- If sufficient money, program sends job to printer automatically without popping up the print screen.- If printed successfully, then program tells user it was printed. I'm able to figure out the rest of the pieces, in regards to user input and determining pages of the pdf, except I don't see how I will be able to print the pdf.

I've tried to use this code

PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService();
DocPrintJob printerJob = defaultPrintService.createPrintJob();
File pdfFile = new File("c://myPdf.pdf");
SimpleDoc simpleDoc = null;
try {
simpleDoc = new SimpleDoc(pdfFile.toURL(), DocFlavor.URL.AUTOSENSE, null);

[Code] ....

But all that I get is junk characters spread across 15 or so pages, for a pdf file that simply says "Hello World". I can open the pdf file on my computer, and print it ok, but when using the above code, it just prints out junk. How I might need to format or setup the pdf so that I can print it correctly. My program could be run on any number of Linux systems, with a multitude of printer types.

View Replies View Related

Java Program That Will Ask A User To Input Grades Until User Inputs Sentinel Value

Apr 9, 2014

Write a java program that will ask a user to input grades until the user inputs the sentinel value -1. The program should test each input to determine whether 0<=grade<=100. If the grade entered is within this range, the program should print "Grade accepted;" if not, the program should print "Invalid input".

View Replies View Related

Where To Input Segment To Get User Input Dialog

Apr 9, 2015

Where do I input this segment?

Scanner user_input = new Scanner( System.in );// This line goes at the top with the other global variables

public void getUserInput(){
System.out.print("Enter litres: ");
litres = user_input.nextDouble( );
System.out.print("Enter mileage: ");
mileage = user_input.nextDouble( );
System.out.print("Enter speed: ");
speed = user_input.nextDouble( );

[Code] ....

This is my client file.

class Client{
public static void main(String []args){
Bike R1=new Bike(5.0, 60.0,30.0);//create bike object with params
Bike R2=new Bike();//without params
System.out.println(R1.increaseSpeed());//calling methods
System.out.println(R1.maxDistance());
System.out.println(R2.increaseSpeed());
System.out.println(R2.maxDistance());
}
}

View Replies View Related

Servlets :: GET HTTP Request Contain A Request Body?

Feb 25, 2014

I have the following questions:

1. Does a GET HTTP request contain a request body? If yes what is contained in it? Are the request headers also part of the request body?
2. Is it possible to send a byte array as part of the GET request in its body?
3. Is there a size limitation on the data that can be sent via a GET request?

View Replies View Related

Largest Of Input Numbers?

Nov 5, 2014

I think the problem in this is that the variable max is initialised as 0. Afterwards it remains in the while loop only, so the output is always 0. I dont know how to bring the last max value out of loop and print it.

import java.util.Scanner;

/**
*
* @author
* @version
*/
public class TEST1

[Code].....

View Replies View Related

Sum And Average Of Input Numbers

Jan 25, 2014

How to create a simple program that can input number from 1 to n. and display the numbers which input by the user and also display the sum and average of it.

Ex.
Please input a number:
1 2 3 4 5 6 7 8 9 10

the sum numbers of 12345678910 is 55
the average number of 12345678910 is ______,

View Replies View Related

How To Get Sum Of All Numbers In A Row Of 2D Array With Row Being Selected By User

Mar 9, 2015

I just learned about 2D arrays and am still trying to get a grasp on the concepts. I'm a little confused by how you return all the values in a row to add up and display the sum if the row is entered by the user.

import java.util.*;
public class RowSum {
public static void main(String[] args) {
Scanner s = new Scanner (System.in);
int userpick = 0;
int sum = 0;

[Code] .....

View Replies View Related

User Must Get Three Random Numbers In A Row - Do While Loop

Feb 12, 2015

I need to fix a program in which the user must get a three random numbers in a row. They have five chances. This is what i have so far:

public static void main(String[] args)throws IOException {
// TODO code application logic here
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int num1=(int)(Math.random()*(9-0));
int num2=(int)(Math.random()*(9-0));
int num3=(int)(Math.random()*(9-0));

[Code] ....

View Replies View Related

Input Validation For Negative Numbers

Feb 20, 2014

I am very new to Java. I have been working for a couple months on a program for school. It has not gone well. I finally was able to scrap together a working program, but i left something out that needs to be. I have to include input validation to check for negative values, prompting users to re-enter values if negative. I have included my current code, the program works perfectly, but what to do about the negative numbers.

Java Code:

package gradplanner;
import java.util.Scanner;
public class GradPlanner {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int numofclasses = 0;
int totalCUs = 0;

[Code] ....

View Replies View Related

Input Validation For Negative Numbers

Feb 20, 2014

I am very new to Java. I have been working on a program. It has not gone well. I finally was able to scrap together a working program, but i left something out that needs to be. I have to include input validation to check for negative values, prompting users to re-enter values if negative.I have included my current code, the program works perfectly, but what to do about the negative numbers.

package gradplanner;
import java.util.Scanner;
public class GradPlanner {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int numofclasses = 0;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: GUI To Add A List Of Numbers Entered By The User

May 9, 2014

I have a GUI with a textArea for the user to input numbers, a button which should "listen" for those numbers, and then a textField to display the sum. I have my code working for user input of one number; but I'm at a loss as to what sort of loop I need to create to get it to read each line of input. I wasn't sure whether to put this in the beginner forum or here, because I am definitely a beginner.

So my code thus far that works with one input:

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

[Code] ....

View Replies View Related

Need To Count Strings That How Many Inputs From User Were Numbers

Jan 30, 2014

import java.util.Scanner;
public class CountStringNumbers { // show the number of Strings that were numbers . . ..
public static void main(String []args){
int count = 0;
int countNumbers=0;
Scanner input=new Scanner(System.in);

[code]...

can count the numbers from 0-9 if the user puted but if it is 10 it doesnt count it , and i need to write all the numbers to have that option. . . . Is there an easy way that includes all the numbers? like if(word.equals(number)){<<<???? (numbers) i know htat doesnt work but is there anything similar ?? ??

countNumbers++;
}
System.out.println("Type Something , , , and to end the the termination type STOP");
word=input.nextLine();
count++;
}
System.out.println("You wrote "+count+" lines wich from those lines "+countNumbers+" were numbers and the programe terminated ");
}
}

View Replies View Related

Output Min And Max Numbers The User Enters - Storing Value

Jul 17, 2014

I need to receive input from the user, as many times as he wants. tha is done with the while loop. I also need to output the min and the max numbers the user enters, therefore i have the if statememnts. also if the user enters only one value i need to output that one value as the min and the max.

int min =0;
int max = 0;
int option = JOptionPane.YES_OPTION;
while ( option == JOptionPane.YES_OPTION){
String dataString = JOptionPane.showInputDialog("Enter an integer");
int data = Integer.parseInt(dataString);

[Code] ....

View Replies View Related

Calculate Factorials Of Numbers 1 Through 10 - Validating Input

Sep 13, 2014

I'm trying to write a program that calculates the factorials of the numbers 1 through 10, based on user input... My problem is that I don't know how to address the possibility of the user entering something other than a number. When I test the following code by entering a letter, I get an Input Mismatch exception. I'd like to be able to inform the user that the entry is invalid, and ask for another response. Here is my program thus far:

Java Code:

import java.util.Scanner;
public class Factorial {
public static String entryString;
public static char entryChar;
public static Scanner input = new Scanner(System.in);

[Code] ....

View Replies View Related

Math On Three Numbers - Get Average / Sum And Number Entered By User

Feb 25, 2015

Java program : For this assignment you are going to write code for the following class:

MathOnThreeNumbers

Here are the specifications of class MathOnThreeNumbers:

Methods of class MathOnThreeNumbers:

1. inputThreeNumbers
2. getAverage
3. getSum
4. getNumberOne
5. getNumberTwo
6. getNumberThree

Constructor of class MathOnThreeNumbers

write a constructor that initializes the first, second, and three numbers to 1, 2, and 3 respectively.

Specs for the methods methods:

1.
name: inputThreeNumbers
accessibilty: public
arguments: none
what it does: asks the user for three numbers of type double

2.
name: getAverage
accessibilty: public
arguments: none
what it does: returns average of the three numbers

3.
name: getSum
accessibilty: public
arguments: none
what it does: returns sum of the three numbers

4.
name: getNumberOne
accessibilty: public
arguments: none
what it does: returns the first number entered by the user

5.
name: getNumberTwo
accessibilty: public
arguments: none
what it does: returns the second number entered by the user

6.
name: getNumberThree
accessibilty: public
arguments: none
what it does: returns the third number entered by the user

Here is an example of how the class MathOnThreeNumbers works. The following code produces the output displayed after the code.

MathOnThreeNumbers mm = new MathOnThreeNumbers();
System.out.println("first: " + mm.getNumberOne());
System.out.println("second: " + mm.getNumberTwo());
System.out.println("third: " + mm.getNumberThree());
mm.inputThreeNumbers();

[Code] .....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved