Exit Program When Nothing Is Input
Apr 16, 2014
If a user inputs nothing the code should end ... How Should i do it?
import java.util.Scanner;
public class MyQueue<T> implements Queue<T> {
private T[] ringbuffer;
static int capacity = 0;
int mysize = 0;
[Code] ....
View Replies
ADVERTISEMENT
Mar 12, 2014
I just want to know how I can get my program to end when the user inputs "0." By using: System.exit(0);
import java.util.Scanner;
public class TestCode
{
public static void main (String [ ]args ) {
Scanner console =new Scanner(System.in);
System.out.println("To exit program input 0");
for (int y = 1; y < 11; y++ ){ // Executes output 10 times
[code]....
View Replies
View Related
Apr 17, 2014
How do i exit a java program is the user input is nothing "",This is my code
Java Code:
import java.util.Scanner;
public class MyQueue<T> implements Queue<T> {
private T[] ringbuffer;
static int capacity = 0;
int mysize = 0;
[code]....
View Replies
View Related
Aug 18, 2014
/* Jessie Garza
* 08 / 18 / 14
* ModCalculator
*/
import java.util.Scanner; // program uses Class Scanner
import javax.swing.JOptionPane;
public class ModCalculator
{
// main method begins execution of Java application
[code]....
I am having troubles with allowing the user to input operations/digits until they want to exit, I have tried looping, but I was unsuccessful, came here hoping to figure this out.Currently I have it ending with Break statements after each switch so that they don't coincide all together.. I can't figure out how to keep the Break statement AND loop to previous code of System.out.println( "Please enter an operand which you would like me to calculate with :");
String st = input.next();
c = st.charAt(0);
System.out.println( "I will need for you to input two integers and I will output the result.");
System.out.print( "Enter first integer to calculate: " ); // prompt
number1 = input.nextInt(); // read first number from user
System.out.print( "Enter second integer to calculate: " ); // prompt
number2 = input.nextInt(); // read second number from user
and allowing it to run through the rest of the program with the options still in tact, while having an if statement of an exit keyword.
View Replies
View Related
Aug 28, 2014
I have been going over my code line by line, over and over again for nearly and hour now...When I execute method `file.createNewFile()`, the method returns true and throws no exceptions. It even says that the file exists. However, the file is not created and cannot be accessed until the program has exited.
File portLib = new File("");
private class RememberPortAction extends AbstractMenuItemAction
{
methods...
protected void actionPerformed() {
LibraryCreator creator = new LibraryCreator(self, logger);
File newPortLib;
[code]....
View Replies
View Related
Oct 1, 2014
Description of the program: read a sequence of positive integers from terminal. When user types
-1, the program will print out the largest number and exit.
Program mid.java
import java.util.Scanner;
public class test
{
public static int num;
public static void main (String[] args)
{
Scanner in = new Scanner(System.in);
num = in.nextInt();
int large = num;
while(num > 0);
{
if(0 > num && num > large)
large = num;
}
System.out.println("The largest number is : " + large);
}
}
View Replies
View Related
Jan 24, 2015
This is my first java program,i am using eclipse IDE-----
package day1.example;
public class MyFirstJava {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("hi");
}
}
When i saved it,it shows no error.when i run it then a pop-up says "could not find the main class.the program will exit" and in the console it says---
java.lang.UnsupportedClassVersionError: day1/example/MyFirstJava : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
[Code] ......
View Replies
View Related
Feb 18, 2014
My question is how can I make the program repeat until the user enters the number 4 to exit?
/**
* Write an application for a furniture company; the program determines the price of a table. Ask the user to choose 1 for pine, 2 for oak, or 3 for mahogany. The output is the name of the wood chosen as well as the price of the table. Pine table cost $100, oak tables cost $225, and mahogany table cost $310. Also ask the user to specify a
(1) large table or a
(2) small table.
Add $35 to the price of any large table and add nothing to the price for a small table. Display the output. Your program must repeat until the user chooses to exit.
*/
import java.util.Scanner;
public class Wood {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
System.out.println ("Table Prices");
[Code] .....
View Replies
View Related
Oct 26, 2014
My homework assignment is: Using a do-while statement, write a Java program that continuously requests a grade to be entered. If the grade is less than 0 or greater than 100, your program should display an appropriate message informing the user that an invalid grade has been entered; a valid grade should be added to a total. When a grade of 999 is entered, the program should exit the repetition loop and compute and display the average of the valid grades entered. Run the program on your computer and verify the program using appropriate test data.
When I run it, I don't get the correct average. I know that i'm supposed to enter 999 to exit the loop and to display the average, but 999 is being added with the loop. I'm not sure how to make it not do that.
//stephanie
import java.util.Scanner;
public class gradeAverage
{
public static void main(String[] args)
[code]....
View Replies
View Related
Jul 14, 2014
So I was going to try to create a program that prompts input and creates a file (That didn't exist before) with that input as name.Then, the program prompts inputs after stating questions such as 1 + 1, then if the user inputs an answer, put "Question # = Correct "or" Wrong.Code SO Far:
Java Code:
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
public class File_Read {
public File_Read() {//File_Read is the Interactive object
[code]....
So that it puts the Correct or Wrong into the file.
View Replies
View Related
Mar 13, 2014
I've spent ages trying to implement an exit button into this code. Its the start of a GUI for a slot machine, the actual machine code is in a separate class and I haven't linked them yet. My question is where/how would the exit button be added? I've tried and failed a lot of times....
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SlotMachineGUI
{
public static void main (String[] args)
{
//create new jframe
JFrame frame = new JFrame ("Slot Machine");
[Code] .....
View Replies
View Related
Apr 11, 2015
I am submitting on a online judge. I am getting NZEC exception in my code
this is my code
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class MyProgram {
static int[] arr;
static int sum=0;
static int x,y,N;
[code]...
what are the causes that is showing NZEC to me?
View Replies
View Related
Mar 5, 2015
This is my code
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
private String[] inputStrings;
private ArrayList<InputField> decodedMessage;
public static void main(String[] args) throws Exception{
new Main().solve();
[Code] ....
This is giving me NZEC exception.I am testing this solution on a online judge.So I don't have any TestCase in which this is failing. So, what are the possible reason of NZEC exception in my code?
View Replies
View Related
Apr 22, 2014
I have a Single Frame Application and I simply want to prompt the user with a dialog confirming they really want to close before they actually close the program, specifically when they click the X in the upper right. I THOUGHT it was like any other java application, with the slight added complexity of having to target the program-created-JFrame with: ".getApplication().getMainFrame()".
MyApp.getApplication().getMainFrame().setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
With that code, DO_NOTHING_ON_CLOSE is set on the JFrame, yet the program closes anyways. Which I don't understand.So I did some reading and found this: URL....That lead me to the configureWindow override, where I successfully tried this:
root.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// write your code here
System.out.println("Window Closing");
}
});
But as far as I can tell that will only let me react to the window closing, not to the command to close it, where I could then kill the command in the dialog if they so "no I'm not ready to quit yet", if that makes sense. So, how to give a prompt before closing?I am using netbeans IDE to create this app - not sure if that is relevant, since maybe it is an oddity with the IDE and not Single Frame Applications.
View Replies
View Related
Nov 22, 2014
Working with the winnings and how to spin again or exit.
import java.util.*;
class Wksht5Q1{
public static void main(String[] args){
Scanner in = new Scanner(System.in);//For user input
Random rand = new Random();//For number generator
//Variables for user input
[Code] ....
View Replies
View Related
Apr 25, 2014
Write a program that allows the user to enter students names followed by their test scores and outputs the following information(assume that the maximum nmber of students in the class is 50; if the number of students is less than 50, to indicate the end of input data, after entering the last students data, on a line by itself, hold the ctrl key/press z and then press the Enter key):
a) Class average
b) Names of all the students whose test scores are below the class average, with an appropriate message( youre below class average)
c) Highest test score and the names of all the students having the highest score.
Use methods.
Now I wrote the program but i cant figure out how to end the input by pressing ctrl key/press z and then press the Enter key...
Here is my code
import java.util.Scanner;
public class ClassAverage {
public static void main(String args[]) {
String names[] = new String[50];
[code]....
View Replies
View Related
Feb 19, 2014
I have to create a program that takes a list of student names and grades and then takes the 2 highest scores and reads them, but the result won't show. I'm pretty sure it's because I'm not sure about how to code the last part which should output the results. Here's my code.
import java.util.Scanner;
//Reads input and outputs 2 highest scores
//for loop. nested for.
public class HighestScores {
public static void main(String[] args) {
//create values
String studentName;
[Code] .....
View Replies
View Related
Mar 12, 2015
A GUI program that allows user to enter their name and the program will convert it in number using array.
For example if i input "EUNISE" the output should be 521149195
Because the letter equivalent of
a = 1
b = 2
c = 3
d = 4
e = 5
f = 6
g = 7
h = 8
i = 9
j = 10
k = 11
l = 12
m = 13
n= 14
o = 15
p = 16
q = 17
r= 18
s = 19
t = 20
u = 21
v = 22
w = 23
x = 24
y = 25
z = 26
View Replies
View Related
Jan 14, 2015
I am trying to create a fortune teller and everything is running fine except the program does not prompt you to answer the questions
Do you like donuts?
and
What did you have for breakfast?
Here is the code this is in Bluej :
import java.util.Scanner;
public class FortuneTeller {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Welcome to Fortune Teller");
[Code] .....
View Replies
View Related
May 19, 2014
So i'm just toying around with making a simple inventory system, and when i'm trying to get the user's input (first the ID number, then the item name, then the item price) it will take the ID number, output asking for the name (but not take any input for it) and then ask for the item's price. I'm really not sure why it's never happened to me before when getting user input.
This is the input part of my code:
public void getInfoAdd() {
int id;
String name;
double price;
System.out.print("Enter ID: ");
id = sc.nextInt();
System.out.print("Enter item name:");
name = sc.nextLine();
System.out.print("Enter desired price: ");
price = sc.nextInt();
addItem(id, name, price);
}
And this is what it outputs:
Quote
Enter ID: 2
Enter item name:Enter desired price: 40
Successfully added: 2 $40.0
View Replies
View Related
Oct 23, 2014
Writing a program to take input from user. This input must be done with numbers only. If the input is a string I would like the program to loop and ask for input again.
double depositCheckingAmount;
do
{
System.out.println("Please insert amount to deposit into checking.");
[Code]....
As you can see my attempt is to use the ! expresssion incase the input does not equal a double. Is there another method I should be using?
View Replies
View Related
Nov 2, 2014
I am writing a program where whatever number I input in my scanner, it will space them...
For example: If I input 456, the output should be 4 5 6... here is my code:
import java.util.Scanner;
public class midterm {
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
String number = "";
[Code] ....
the current output for this program is:
456 456 456
View Replies
View Related
Feb 3, 2014
I am stumped on a coding project I am working on. I am making an inventory program with predefined values for the items. I am not sure how to iterate through my arrayList, and allow the user to input the "number sold."
I have made an arrayList and populated it using the add(), but I am not sure if it is working correctly. This is my inventoryItem class :
package inventory;
import java.text.DecimalFormat;
public class inventoryItm {
String itemName;
double unitPrice;
int numberSold;
[Code] .....
View Replies
View Related
Feb 11, 2015
I am trying to read contents from a file and display them to the user. However, when I enter the file into the program I get the following error: "exception in thread 'main' java.util.MismatchException. What am i doing wrong?
import java.util.Scanner;
import java.io.*;
public class Project1{
public static void main(String[] args) throws FileNotFoundException {
double balance;
double item1Price;
[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
Feb 24, 2014
I am trying to write a program in Java that uses threads.Below is the program requirements:The goal of this assignment is to create a routine which creates multiple threads, has them do work in parallel, and terminates when the last thread has finished.
The Scenario: There are several groups of people in a bar watching the Olympics cheering for their country. Each group will cheer for their country some given number of times, with a random pause (between 2 and 5 seconds) between each cheer. There is enough room at the bar for up to ten different groups to sit (each would be cheering for a different country).
The Program: The task is to write a program that will simulate these cheers using threads. The program should be called cheer.X (X being the language of choice). You may use any language that supports threading. When the program is run it should ask for the number of countries and then the name and how many times it will be cheered for. The main function will then create a thread for each team and each thread is responsible for cheering the specified number of times for the correct team at the random interval. You will submit the proper source code file for me to open and compile myself, not an executable.
An example run would look something like this: How many countries are supported at the bar? 3 Enter the first: China How many cheers? 2 Enter the second: USA How many cheers? 4 Enter the third: Russia
View Replies
View Related