How To Stop Program When Entering Certain Number

Dec 2, 2014

how many integers the user wants to use. The user will enter for example a 4. The user inputs a 2, 4, 6, and 10. So then we get our outputs...Then the code will ask if you want to run this program again. My question is, if the user inputs a -1 for example 2, 4, 6, -1....the code will not continue. I wanted to use a while loop, such as while (scores != -1) but it doesn't work.

Enter the amount of integers you want to use4
Intenger # 1 2
Intenger # 2 4
Intenger # 3 6
Intenger # 4 10
You entered 2.0 4.0 6.0 10.0
Average = 5.5
Variance = 8.75
Standard Deviation = 2.96
Do you have another set of numbers?

[code]....

View Replies


ADVERTISEMENT

Stop User From Entering A Negative Number

Apr 4, 2014

i am writing a program that would be used for ticket sales and their are 100 tickets and a person can only buy 4 at a time. i need my program to not go negative at the end and also i need to stop the user from entering a negative number.

import java.util.Scanner;
public class ticketmaster {
public static void main(String[] args) {
// Variable decoration uses strings , doubles and final doubles.
Scanner in = new Scanner(System.in);

[code]....

View Replies View Related

Stop User From Entering A Negative Number

Apr 4, 2014

i am writing a program that would be used for ticket sales and their are 100 tickets and a person can only buy 4 at a time. i need my program to not go negative at the end and also i need to stop the user from entering a negative number here is the code.

import java.util.Scanner;
public class ticketmaster {
public static void main(String[] args) {
// Variable decorationuses strings , doubles and final doubles.
Scanner in = new Scanner(System.in);

[code]....

View Replies View Related

Stock Program - Stop User From Entering In Textfield And Display Message When Stock Is Low

Jun 29, 2014

I'm trying to make a stock program that stops the user from entering in textfield and displays a message when stock is low. There's just 2 problem the entered value by the user is only decremented twice then the total stock resets for example with SofaTotal and the if statement doesn't work:

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.text.DecimalFormat;
import java.util.Arrays;

[Code] .....

View Replies View Related

Searching / Entering Name And Number

Jun 28, 2014

import java.io.*;
public class pho
{
public static void main (String args[]) throws IOException
{
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String name = new String [50];
long phn = new long [50];
System.out.println("enter A for adding phone numbers");

[Code] .....

View Replies View Related

JOptionPane / Entering Valid ID Number

Oct 5, 2014

I am working on allowing a user to enter an ID # using JOptionPane. If the ID is valid, then it will display the ID#, student name, and GPA. If it is not valid, then the window should pop up again to allow the user to enter a valid ID. I have managed to get that far.

I am struggling with once a valid ID # is entered, how do I get the loop to stop? I have tried several different ways, but the code below is the most recent one, and it is still not working!

import javax.swing.*;
public class StudentIDArray
{
public static void main(String[] args)
{
String enteredID;
int idNumber;
int x = 0;

[Code] .....

View Replies View Related

Why Program Not Entering If Statement

May 5, 2014

package catalog;

import java.util.*;
public class Catalog {
static String products[] = new String[3];
static int answer;
public static void main(String[] args) {

[Code] ....

View Replies View Related

Number Guessing Program - Computer Guesses A Number That User Is Thinking Of Within Certain Range

Mar 28, 2015

I have a beginning Java Program I have been working on that creates a number guessing program where the computer guesses a number that the user is thinking of within a certain range. I so far have the program below, but need getting rid of a few kinks/ adding features.

-First, I need to set it up so that the user will be prompted and give a range. It should run and produce something like this:

Welcome to this first-ever mind-guessing program!

Please pick a range (higher than 1 and no larger than 50): 32

You will choose a number between 1 and 32... and I will try to guess it.

With each of my guess, you will tell me whether I am too high (h or H), too low (l or L), match (m or M), or you want to quit (q or Q). My objective is to find the number using as few guesses as possible.

-Second, the game is supposed to give up and restart after failing the five, guesses, but for some reason, after it fails the fifth time, it prompts a fifth guess once again instead, then restarts after- I need to prevent this, so that it should look something like this:

My fourth guess is 17: h
My guess is too high?

My fifth guess is 16: h
*** I am unlucky this round. I give up.

Let's play!

My first guess is 10:
etc..

import java.util.*;
import java.lang.Math;
public class numguessprac1 {
// Declaring variables
public static String input;
public static int quit;
public static int guess;
public static int wins;

[Code] ....

View Replies View Related

Program That Takes A User Inputted Number And Converts It To A Binary Number

May 5, 2014

trying to write a program that takes a user inputted number and converts it to a binary number.

Here's what I have:

package com.java2novice.algos;
import java.util.Scanner;
public class Converter {
static Scanner console = new Scanner(System.in);
public void printBinaryFormat(int number){
int binary = console.nextInt();

[Code]...

Bugs on:

Line 13
Line 17
Line 23

View Replies View Related

Program Is To Accept Number And Display New Number After Removing All Zeros

Dec 29, 2014

ex
Sample input:2340980
Sample Output:23498

this is the program i have tried but is dosent work

import java.util.*;
class zero
{
public static void main(String args[])
{

[Code]....

View Replies View Related

Create Little Program Which Enter Number / Program Says Triangle Exist Or Not

Mar 16, 2014

i want create little program which enter the number, ant program says triangle exist or not. So code :

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

[code]...

So when i put first num like 1, next num like 2 and next num like 100 , program says Triangle exist.

View Replies View Related

Use Tag Object Or Applet For Entering Class Name Data

Sep 30, 2014

I have problem with this applet. the browser gives page.I don't know wether its not loading or if its extremely slow.Also I am confused on the html part.Should I use tag object or applet and for entering class name data,classid or name.

import java.lang.reflect.InvocationTargetException;
public class NewJApplet extends javax.swing.JApplet {
@Override
public void init() {
this.add(fesText);
this.add(jButton1);
this.add(jLabel1);
this.add(jLabel2);
this.add(jPanel1);

[code]....

View Replies View Related

Movie Arrays - Entering 2 Movies / Accepts Only 1

May 8, 2015

whats the problem in my code : if i enter 2 movies are being displayed,it accepts only 1.

The code:

class theatrebooking {
public static void main(String args[])throws IOException {
Scanner in=new Scanner(System.in);
System.out.println("********************************************************************************************");
System.out.println();
System.out.println("System requires updation");

[Code] ....

View Replies View Related

Java Arrays - Entering Lists Only Let To Enter 2 Numbers?

Oct 9, 2014

I am trying to write a code that allows you to input 2 lists and it tells you if they are identical or not. However, when I enter my fist list I can only enter two values and then it asks for the next list. How would I fix this to allow me to enter more than two values?

Also, If the second list is different it has me enter more values that list one.

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
  // Enter values for list1
System.out.print("Enter list1: ");
int size1 = input.nextInt();
int[] list1 = new int[size1]; 
for (int i = 0; i < list1.length; i++)
list1[i] = input.nextInt();
  // Enter values for list2
System.out.print("Enter list 2: ");

[code]...

My output looks like this:

Enter list1: 1
2
Enter list 2: 2
3
2

Two lists are not identical

View Replies View Related

Entering CLASSPATH In Manifest File When Directory Is Not In Root?

Jul 1, 2014

I'm trying to add a CLASSPATH to a manifest file linking (not sure If that's the right word) to an sqljdbc4.jar file.

If I copy the file Into my root folder and use CLASSPATH: sqljdbc4.jar It works fine.

Class-Path: sqljdbc4.jar
Main-Class: com.ncntech.go

If I try CLASSPATH: C:Program FilesMicrosoft JDBC Driver 4.0 for SQL Serversqljdbc_4.0enusqljdbc4.jar I receive a "Could not find or load main class" error.

Class-Path: C:Program FilesMicrosoft JDBC Driver 4.0 for SQL Serversqljdbc_4.0enusqljdbc4.jar
Main-Class: com.ncntech.go

Is the syntax correct for specifying a directory path ?

View Replies View Related

Swing/AWT/SWT :: JTabbedPane / Method Call When Leaving A Tab And When Entering Another One

Mar 16, 2014

I think, is of concern to a large Swing-JTabbedPane users and which does not appear in the Sun-Oracle tutorial [URL]

How to add functionality to the hidden 'Action Listener' of JTabbedPane to obtain the two following functionalities, when passing from Tab_Panel_1 to Tab_Panel_2 ?

- To call a home made function as very last task when the 'tab selection change' is triggered and just before control and visibility are leaving Tab_Panel_1.

For example : Calculations and table fillings need to be operated. One assume that the fact of leaving Tab_Panel_1 (by clicking another 'tabPanel') means that the input data in Tab_Panel_1 are completely introduced and that calculations and/or table fillings may occur (to be used by other 'Tab_Panel's).

- At the moment of entering Tab_Panel_21 or Tab_Panel_22, the very first task is to use the previous calculation results and/or table fillings as input parameter of methods own to Tab_Panel_21 and Tab_Panel_22.

For example, these data are further processed and used to feed a graph, different for Tab_Panel_21 and Tab_Panel_22.

tabbedPane.addChangeListener(new ChangeListener()?
SwingWorker?
SelectionChanged?

View Replies View Related

Swing/AWT/SWT :: Rows In JTextArea - Entering More Lines Than Limit

Jan 9, 2014

Here's a snippet of code from a program I'm making:

private void init() {
...
testInfo = new JTextArea("Progress log:
");
testInfo.setEditable(false);
testInfo.setLineWrap(true);
testInfo.setPreferredSize(new Dimension(testInfo.getPreferredSize().width, 200));
scrollPane = new JScrollPane(testInfo);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
...
add(scrollPane);
}

The problem is, the JTextArea that's created has a "limited" number of rows - it seems you can still enter more lines than the "limit", but they don't show. I thought it was a problem with the JScrollPane but I'm not so sure...

View Replies View Related

Two Options To Stop Do While Loop?

Oct 11, 2014

In the code that I am currently trying to do, I want to make it so that the program loops until the randomly generated number is 1, to a maximum of 4 loops.I have figured out how to make it stop at a randomly generated 1, but I can't quite figure out how to make it stop at four loops if it doesn't reach the 1 before the maximum number of loops.

View Replies View Related

Swing/AWT/SWT :: Application Just Stop Itself During Execution

May 18, 2014

I made a check4 application with Java.It correctly works but sometimes the application just stop itself during the execution.I never had a problem like this. The application just stop itself and i can't even quit using the closing button..

View Replies View Related

How To Stop Infinite Loop Programmatically

Mar 24, 2015

I am developing application called java compiler... It takes java program as input and compiles and run it, gives output. but if input program has infinite loop then how can identify and stop process execution.

View Replies View Related

Play / Stop And Loop Three Different Songs

May 13, 2014

I am making a project that should play, stop, and loop three different songs (not at the same time). I am calling this SoundPlayer class from my main class:

import javax.sound.sampled.*;
import java.util.*;
public class SoundPlayer {
List<AudioInputStream> songs = new ArrayList<AudioInputStream>();
int currentSong, currentPlayType;

[Code] ....

When my class calls setPlayType(2), which should make it play, I get the following runtime error:

java.lang.NullPointerException
at SoundPlayer.playSong(SoundPlayer.java:32)
at SoundPlayer.setPlayType(SoundPlayer.java:64)
at MainPanel$AListener.actionPerformed(MainPanel.java:60)
(...)

Line 32 is if(clip.isOpen()), but I'm pretty sure I instantiated clip properly in the constructor.

View Replies View Related

Get Code To Stop Overwriting The Output?

May 1, 2014

What I mean is, I have this set and it is supposed to take out all the duplicates. If I enter aaabbbcccd the output should be abcd, but instead my code just outputs the last word, or in this case letter entered.

import java.util.*;
public class setdemo
{
public static void main(String[] args)

[Code]....

View Replies View Related

Any Way To Stop Duplicate Links From Getting Put In ArrayList

Oct 5, 2014

I am making a WebCrawler, and I am trying to work out a way to stop duplicate links from getting put in however ArrayList.contains() doesnt seem to be working for me can someone look at my code and see if I am doing something wrong? I have also tried variations of it such as

!link.contains(newLink)
and
!link.contains(newLink.getLinkUrl())

with no luck. The Problem area is

for(Element lnks: link){
linkSrc = lnks.absUrl("href");
WebPage newLink = new WebPage(linkSrc);
if(!link.contains(linkSrc)){
links.add(newLink);

[Code] .....

View Replies View Related

How To Make Animation Stop Randomly

Dec 28, 2014

I am trying to program a slot machine and as of now, I am trying to make my slots spin and randomly stop on one of the graphics. Right now, I am having difficultly making the animation/slot stop randomly.

Previously, I tried using a randomly set timer that would cancel the execution, but the image did not appear/stop on the screen.Right now, I am using a random generator and a while to say that if it is a certain number, then stop the image.Here's what I tried:

import java.applet.*;
import java.awt.*;
import hsa.*;
import java.util.Random;

public class SlotGraphics
{
Console c;
int x = 200;
int y = -100;

[code]....

View Replies View Related

Java-8 :: How To Stop Infinite Stream

May 26, 2014

I have a Stream instace which produces values using an infinite Supplier (it supplies values taken from an electronic sensor -- so unless the battery is low, the sensor will provide "for ever").

The stream is processed by a Collector using Stream.collect() (e. g. imagine that the values from the sensor should be averaged; in fact what it does is a bit more compliacted maths).

The problem is that the collector does not produce a result but hangs up, as the supplier does never stop providing more sensor values.

So what I need is a limitation rule that stops the stream. While there is a Stream.limit(long) method, it actually does not solve my problem as in my case it is not practical to stop after a particular count, while I actually want to stop streaming when the sensor value exceeds a particular limit etc. (hence, voids an arbitrary rule).
 
To sum up, what I need is Stream.limit(Predicate), i. e. the stream will stopped once the predicate becomes true.
 
Unfortunately I did not find anything like that in JRE 8.
 
Is that planned for JRE 8.1 or JRE 9.0? Or is there a known (and sophisticated) workaround?

View Replies View Related

Perfect Number Program

Oct 28, 2014

import java.util.Scanner;
public class pdonahue_Perfect
{
public static void main (String args[])
{
int test;
int value=0;
Scanner input = new Scanner(System.in);

[code]....

i have just a couple of issues when running my program.
-First, When i enter 0 it should print..

Please enter a possible perfect number: 0
0:NOT PERFECT

-Second, when i get a perfect number. it should show the answer in descending order..

Please enter a possible perfect number: 6
6:3 2 1

mine shows: Please enter a possible perfect number: 6 6: 1 2 3

**everything else compiles correctly with no errors

View Replies View Related







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