Changing For Loop To While Statement?

Aug 23, 2014

I am having trouble doing a simple exercise changing a for loop to a while statement, it works fine in the for loop but in the while statement it just prints out 10(it is supposed to count to 0 and print liftoff).

public void run() {
int i = 10;
while (i>=1) {
println(+i+"...");
i--;
}
println("liftoff..."); 
 }

View Replies


ADVERTISEMENT

GUI Log - IF Statement / For Loop

Nov 29, 2014

I've done a basic login GUI for a application, a user enters their name and address and clicks register, a four digit pin is then randomly generated, the pin and name and address are all added to an object of the MemberDetails class , this obj is then added to an array list.

returning customers can then enter a previously generated pin and either get a welcome back message or an invalid pin message.

my issue if i register two new users and get their generated pins, that on the returning members screen it will only show the welcome message for the second new customer i created and not recognizing the first customers pin. heres my code:

taking in new customer details, generating pin , adding obj to arraylist

int randomPIN = (int) (Math.random() * 9000) + 1000;
members = new MemberDetails();
members.name = nameNew.getText();
members.address = addressNew.getText();
members.pin = randomPIN;

[Code] ....

that lest method is a bit of a mess i know, i was going to store the log in attempts in a array but thats probly not a good tactic, and that inner for loop is probly unnecessary ?

View Replies View Related

Looping Through While Loop With Switch Statement?

Sep 23, 2014

I am having a problem with looping a while loop that contains a switch statement. Here is my code:

package hw4jenningsd;
import javax.swing.*;
public class HW4JenningsD {

[Code].....

View Replies View Related

Can Insert While Loop In Switch Statement?

Dec 8, 2014

I am trying to add a while loop into my switch statement. If you run the program, it will ask to enter the class grade (9,10,11, or 12). If you insert 5, it will say to try again. But, if you enter a wrong number twice, it will continue on to the next part of the program, which is asking how many students are in the class. Therefore, I believe a while loop would work, but it is not working at all. The program still runs, just doesn't fix the error. The program is below:

import java.util.Scanner;
public class stephProject {
public static void main(String[] args) {
//call method
welcomeMessage(); //method 1 of 3

[Code] ....

View Replies View Related

Use While Loop With Input And If Statement For Output

Apr 26, 2015

Here is my code so far. I am trying to get the WHILE LOOP to work so the user inputs a number, the if statement prints the output and then it returns to ask for another number and goes again and again looping :

import java.util.Scanner;
public class ifwhileloop {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
double nmbr;

[Code] ....

View Replies View Related

If Statement Won't Work Inside A While Loop

Dec 12, 2014

I made this calculator in C++ and it worked wonderful so I decided to make it in java. When I run the program it gives me no errors but my if statements inside my while loop don't work

import java.util.Scanner;
public class ohmlaw {
public static void main(String args[]) {
float current;
float resistance;
float voltage;
String calchoice = new String();
Scanner cc = new Scanner(System.in);

[code]....

View Replies View Related

Switch Statement Inside While Loop

May 5, 2015

cannot break from while loop. Whenever I am trying to exit from startCustomerManagement-> backEnd() -> mainScreen()..It gets stuck between mainScreen and backEnd screen. However I can exit from backEnd()->startCustomerManagement() screen

/*
* 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.
*/
package javaapplication19;
import java.io.BufferedReader;

[code]...

View Replies View Related

Counting Input Array - For Loop Statement

Mar 13, 2014

I have to take user input and then count how many times each number that the user input and print each one out. For some reason, I can't even get the for loop statement to print and it's pretty much the same as my other program except for the loop which is a little different.

//User inputs numbers between 1 and 100, program counts how many of each integer is and ends with a 0
 
import java.util.Scanner;
 public class occurrence {
 public static void main(String[] args) {
 //scanner/values
Scanner input = new Scanner(System.in);
int number = 0;
int c = 0; //array count
 
[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

Counter Controlled Loop With A Switch Statement

Sep 28, 2014

I'm trying to create a switch statement inside of a counter controlled (while) loop that asks for an input of...

"How many characters would you like to convert?"

Then you type in a number > 0, and then it should convert letters into the "1337" equivalent.

This is an example on what it should do.

How many characters would you like to convert? 5
Enter character #1 to convert: !
!-
Enter character #2 to convert: $
$-
Enter character #3 to convert: #
#-
Enter character #4 to convert: *
*-
Enter character #5 to convert: ,
, -

Whenever i try to run the program, i only get the- How many characters would you like to convert- i input 5 but then nothing else prints..

My codes..

System.out.print ( "How many characters would you like to convert?: " );

int convertCounter = 1;
char ch;
ch = input.next().charAt(0);
while (convertCounter > 0)
switch ( ch ){

[Code] ....

View Replies View Related

Java Statement Getting Executed Multiple Times Outside For / While Loop

Aug 14, 2014

I am trying to execute the following method: This method takes a delivery date as one of the arguments and a list of calendar holidays as another argument. If the delivery date is present in the holiday list, I will add 1 day more to the delivery date and check again if the new delivery date is part of holiday list.

Issue is that the last 3 statements before 'return' are getting executed multiple times though there is no for or while loop. Why they are getting invoked multiple times.

@SuppressWarnings("rawtypes")
private String fetchNextWorkingDay(String sDeliveryDate, Element eleCalendarDayExceptions, SimpleDateFormat sdf, Format formatter) throws Exception {
System.out.println("");
System.out.println("Inside fetchNextWorkingDay method");
System.out.println("Del Date to compare is "+sDeliveryDate);
Boolean isDateSet = true;

[Code] .....

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

Unable To Print A Loop Inside Array Of Greater Size Than Loop Itself

Jan 27, 2015

I am trying to print a loop inside an array of a greater size than the loop itself. Like for example I have an array of size 7 but it has only 3 elements.

int[] array=new int[7]
array[0]=2;
array[1]=3;
array[2]=4;

now what I want to do is print these three numbers in a loop so that my array[3]=2;array[4]=3;array[5]=4 ...... till the last one. Also the array could be any size and not just 7.

View Replies View Related

While Loop Inside A For Loop To Determine Proper Length Of Variable

Feb 25, 2014

Here's the code: it's while loop inside a for loop to determine the proper length of a variable:

for (int i = 0; i < num; i++) {
horse[i]=new thoroughbred();
boolean propernamelength = false;
while (propernamelength==false){
String name = entry.getUserInput("Enter the name of horse "

[code]....

I was just wondering what was going on here -- I've initialized the variable, so why do I get this message? (actually the carat was under the variable name inside the parentheses.

View Replies View Related

When Type Quit To Close Outer Loop / It Still Runs Inner Loop

Nov 2, 2014

I have everything else working. My problem is that when i type "quit" to close the outer loop. It still runs the inner loop. The National Bank manager wants you to code a program that reads each clients charges to their Credit Card account and outputs the average charge per client and the overall average for the total number of clients in the Bank.

Hint: The OUTER LOOP in your program should allow the user the name of the client and end the program when the name entered is QUIT.In addition to the outer loop, you need AN INNER LOOP that will allow the user to input the clients charge to his/her account by entering one charge at a time and end inputting the charges whenever she/he enters -1 for a value. This INNER LOOP will performed the Add for all the charges entered for a client and count the number of charges entered.

After INNER LOOP ends, the program calculates an average for this student. The average is calculated by dividing the Total into the number of charges entered. The program prints the average charge for that client, adds the Total to a GrandTotal, assigns zero to the Total and counter variables before it loops back to get the grade for another client.Use DecimalFormat or NumberFormat to format the numeric output to dollar amounts.

The output of the program should something like this:

John Smith average $850.00
Maria Gonzalez average $90.67
Terry Lucas average $959.00
Mickey Mouse course average $6,050.89
National Bank client average $1,987.67

Code:

public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String name = "";
int charge = 0;
int count = -1;
int total = 1;
int grandtotal = 0;
int average = 0;
 
[code]....

View Replies View Related

Changing JPG DPI Value For Some Images

Sep 25, 2014

I am currently working on Java software which resize jpeg images and change DPI also. For JPEG images having app0JFIF node it works fine and the images new DPI is reflected in Photoshop. But if app0JFIF node not exist, I am trying to create a new one and set the DPI value there. Everything is going proper but if I open these images in photoshop it does not reflect new DPI but the size changes.

Java Code:

double dpi_in_inch = 0.393701 * newres;
File file1 = new File(imgName);
image = ImageIO.read(file1);
int wd, hi;
wd = (int) (newsize * dpi_in_inch);

[Code] ...

View Replies View Related

Changing Superclass Parameters?

Jul 16, 2014

My understanding was I could override a method from the superclass, including with different parameters, but when I try to use super. it gives me an error the arguments have to match the superclass. But, if I do that it won't make any sense.

The first code below is the superclass. The issue I'm having is on the second code at lines 7 and 10. The ultimate goal is to make a new class where I'm able to display various packages with or without insurance.

public class Package {
double shippingWeight;
public char shippingMethod;
final char air = 'A';
final char truck = 'T';
final char mail = 'M';
double shippingCost;

[code]....

View Replies View Related

Changing Hour To Minutes?

May 1, 2014

I have a servlet with a method:

/**

* @return <code>double</code> Hours
*/
public double getDriveHours() {
return getAsDouble("DriveTime", 0.0D);
}

I would like to change the time to minutes. I will create a new entry in the db for the minutes, but wondered if the time minutes is also double.

View Replies View Related

Changing Values In Different Programs?

May 20, 2014

I'd like to make a simple cheat for an old game that's offline... It has no type of anti-cheat and I'd like to make a program that changes how much money you have... I think the first thing I have to do is get the data address or something like that by using cheat engine... How do I do that? After that how do I start using that info in my program and then send back a new value? Are there any classes that I should be importing and what methods do I use to do this?

View Replies View Related

Swing/AWT/SWT :: Color Is Not Changing

Jan 29, 2015

Color only changes, when resizng frame with mouse, not when clicking.

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class SimpleGui1 implements ActionListener {
JFrame frame;
MyDrawnPanel drawnPanel;

[Code] .....

View Replies View Related

Changing Format For Timer?

Mar 17, 2014

im making a javabean for stopwatch which works perfectly, but i want in the property descriptor format, so the user can change its format.

currently i have;

private String displayFormat = "MMMM d, yyyy h:mm:ss";
private SimpleDateFormat formatter;
public synchronized void setDisplayFormat(String newFormat) {
String oldFormat = getDisplayFormat();
try {
formatter.applyLocalizedPattern(newFormat);
timerHasPinged();

[code]....

currently the timer works its format is in 00:00 minutes:seconds, but i want it to start as MMMM d, yyyy h:mm:ss, for example March 17 2014 00:00:01, so only one second has passed here. i believe the set and get format method is fine but the timerhaschanged needs to change as this is where the format takes place.

View Replies View Related

Changing Ints From Another Class

Jun 27, 2014

I am making a simple text based game and i have a monster, and I am tring to make its health go down whent he user input "s" but istead it doesnt change and the users health even goes up.

Main.java

package exodus.game.main;
import java.util.Scanner;
import exodus.game.monsters.Nirav;
public class Main {
static String name;
static String inputtemp;

[Code] .....

View Replies View Related

JTextArea Changing Txt File

Apr 24, 2014

Every time I load a txt file into a JTextArea it prints the results to the JFrame incorrectly I notice its mainly the white spaces this is happening to. I have tried a few ways to remedy this problem but it still keeps occurring? I've tried append() read() also setText() even Scanner. I have enclosed a picture of my GUI and my txt file I am using.

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
import javax.swing.JFrame;
import javax.swing.JTextArea;

[Code] ....

Attached image(s)

View Replies View Related

Creating UML And Changing Color?

Oct 20, 2014

The Toys of the Future Company has decided to issue a new line of toy robots. While they are not sure exactly what their robots will look like, they do know the functionality that they will all have. All robots will be able to move forward, turn right, turn left, spin and detect an object in front of it via a sensor. The robot will use a touch sensor to determine whether it has hit an object in front of it, such as a wall. The robot will have two, three, or four wheels, but it will only be driven by two of them: a right wheel and a left wheel. Each wheel will be attached to a motor that controls it.

* ^ this is only something to think about
Produce a UML class diagram.

Using UML, describe the objects and classes that will be associated with this new toy. Either hand draw or use an appropriate UML creation tool to generate a UML design document for your Robot class. Create a set of classes that can be used to control the robot.

Develop your new class.

Create a new NetBeans project entitled, "Assignment_8_1" and develop your new class. Now, using the objects and classes that you have written, write a program for your robot that allows it to move in a large square. Allow your robot to run in a big two dimensional array and every time the robot encounters a square in your array, turn that square black.

So here is the code for the moving ball:

package ballapplet;
import java.awt.*;
import java.util.Formatter;
import javax.swing.*;
public class BallApplet extends JPanel {
private static final int BOX_WIDTH = 640;

[Code] ....

I want to know how to change the color of an object, and how to move it in specific directions.

View Replies View Related







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