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


ADVERTISEMENT

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 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

Create A Program That Will Check If One Statement Is Equal To Another

Dec 5, 2014

I'm suppose to create a program that will check if one statement is equal to another but it doesnt display the message if its equal to the inputted String

import java.util.Scanner;
 
public class sup {
public static void main (String args[]) {
Scanner in = new Scanner (System.in);
String one;

[code]...

thats just an example I was able to do it in C++ but it doesnt do what I want in Java

View Replies View Related

Argument Program - Missing Return Statement

Jan 22, 2015

I am trying to compile the arguments program but it is giving missing return statement error. how to correct the error message.

public class Arguments {
public static Void main ( String args[])
{
int count, i=0;
String sdata;

[code]...

View Replies View Related

Program Involving For Loop And If Statement Not Working

Oct 23, 2014

Alright so I'm trying to write a code that implements a for loop and if statements that displays any number from 100-200 if the number is divisible by either 5 or 6 in rows of ten numbers each row. If it is not divisible by that number then it should go back to the beginning of the loop until it reaches 200. My main problem is that it doesn't display anything. I don't get any errors or anything but every time I run the program it just displays nothing. Sample output is at the bottom of the code.
 
public class Exercise5_11 {
public static void main(String[] args) {
int count = 0;
int i = 100; 
//for (the numbers from 100 to 200)
for (i = 100; i>100 && i<200; i++){
 
[Code] ....

/*Output
100 102 105 108 110 114 115 125 126 130
132 135 138 140 144 145 155 156 160 162
165 168 170 174 175 185 186 190 192 195
198 200
*/

It is still wip of course so I was trying to just get it to display int i but it doesn't do anything and I'm not really sure why.

View Replies View Related

Program Ask For Five Names Using Loop Statement And Print All

Jan 24, 2014

write a program that would ask for the five names using loop statement and print all names .

View Replies View Related

Cash Register Program For 5 Products Using Switch Or If Else Statement In Java

Dec 3, 2014

We're told to make a cash register program for 5 products using Java. It loops until "-1" is entered on the "Continue?" input dialog box.There should be a:

1. Main Menu - where the user will pick what to buy (one product at a time) like the sample code below and prompt the user if he will buy another product or not. If yes, the program will go back to the main menu to buy another product and if not, continue to the program. And it looks something like this: LEvFOwQ.png

2. Receipt - at the end of every transaction.

3. Daily Sales Report where it shows all receipts then grand total like:

Transaction 1

-subtotal

Transaction 2

-subtotal

and so on then,

GRAND TOTAL

4. Inventory Report where it shows the Items Available before the Selling, Items Sold, and Items Available after Selling in table format.

Below is the code for a simple cash register for only one product that I made but I need to upgrade it for it to work for 5 products. That code will serve as the basis for this program.make the switch or if-else statement for the main menu first and if I got it right I try doing the rest.

int userQty1 = Integer.parseInt(JOptionPane.showInputDialog(
"Product ID Product Name Product Quantity Product Price"
+prodID1 + " " +prodName1 + " " + prodQty1 + " " +prodPrice1 "
"
+ and so on until prod5));

[code].....

View Replies View Related

Program Outputting Null Into Validation Statement - Runtime Error

Oct 17, 2014

I am Having trouble with my program to validate. It is outputting null into the validation statement then it brings back a run-time error to that validation Statement for the String.

public String validateData ()
{
if (nm == null)nm = "Error! Must enter at least one character";
else nm = name;
return name;
}//end validation method

Why is this happening, and then once that is completed, why is the validation Sentence in tests Scores not able to validate. I traced it back to out put "Error, a number between 1<100".

public void validateTests ()
{
String testschange;
if (test1 < 0 || test1 > 100) {
testschange = " You have entered an invalid number, between 1-100. Please restart!";
testschange = Integer.toString( test1 ) ;

[Code] .....

View Replies View Related

When Remove Increment Operator Program Shows Invalid Statement

Feb 19, 2015

class Brain56
{
public static int[] get()
{
return null;
}
public static void main(String...a)
{
int k=1;
get()[k]++;
}
}

when i remove the increment operator(get()[k]) program shows invalid statement may i know the reason behind it?

View Replies View Related

Writing A Program Using Switch Statement - Allow Users To Choose Item Of A Menu

Oct 5, 2014

Write a program using switch statement to allow users to choose an item of a menu. For example, the menu looks like the following.

File menu
1. Open
2. Close
3. Save
4. Exit
Enter your choice:

If you type 1, then your program should print out "Open is selected" (double quotes not included).

Notice:
(1) Using Scanner to get user choice;
(2) If the number user input is not in {1,2,3,4}, your program should let user know that.

Here's what I have:

public static void main (String[] args) {
int user = 1
switch (1) {
case value: 1
System.out.println ("Open is selected");

[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

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

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

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

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

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

How To Turn If Statement Into A Case / Switch Statement

Jun 19, 2014

So from what iv learnt in Java and programming in general is that using a case statement is far more efficient that using multiple IF statements. I have an multiple IF statements contained within a method of my program, and would like to instead use a case statement.

public String checkPasswordStrength(String passw) {
int strengthCount=0;
String strengthWord = "";
String[] partialRegexChecks = { ".*[a-z]+.*", // lower
".*[A-Z]+.*", // upper
".*[d]+.*", // digits
".*[@#$%!]+.*" // symbols

[code].....

View Replies View Related

Using Switch Statement Inside If Statement

Nov 18, 2014

So I want to make a simple Java that ask the user to pick a powers and it has two options.If the user picks magic then execute the first if statement then ask the user again which type of magic the user wants.I can't make it work it keeps printing the else statement. Why is that?

import java.util.Scanner;
public class Variable {
static Scanner zcan = new Scanner(System.in);
public static void main(String[] args)

[code]....

View Replies View Related

How To Run If Statement

Apr 5, 2014

I'm trying to run an if statement with an input condition and here is my code.

import java.util.Scanner;
public class App10A {
public static void main(String[] args) {
Scanner fun = new Scanner(System.in);
System.out.println("What's your name?");
String name = fun.nextLine();

[code]....

When the computer asked me "What's your name?", I typed in Victor, then the result turned out to be "Oops, try again!".I typed in Victor (without parenthesis) and "Victor" and both gave me the negative results.What exactly should I put in in order to get "This is the result I wanted!" ? how should I modify my code in order to get "This is the result I wanted!" when I put in Victor (without changing the equal sign)?

View Replies View Related

How To Use Variable In If Statement

Feb 17, 2014

How do I use a variable in an if statement to return a public void method from another class? I've tried:

System.out.print("select 1 - 6: ");
Scanner myScanner = new Scanner(System.in);
myScanner.nextInt();
if (myScanner.nextInt()==1) {
carSelection colour = new carSelection();
colour.carSelection();

The method colour in class car selection is just 4 print line statements? I've // out the if statement to see if it is correctly calling the method and displaying the data and it is?

View Replies View Related







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