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


ADVERTISEMENT

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

While Loop Involving Odd And Even Integers

Oct 9, 2014

My instructions are to:

1. Prompt the user to input two positive integers: firstNum and secondNum (firstNum must be smaller than secondNum).
2. Output all the even numbers between firstNum and secondNum inclusive.
3. Output the sum of all the even numbers between firstNum and secondNum inclusive.
4. Output all the odd numbers between firstNum and secondNum inclusive.
5. Output the sum of all the odd numbers between firstNum and secondNum inclusive.

*Use while loop
int firstNum, secondNum;
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter an integer: ");
firstNum = keyboard.nextInt();

[Code] ....

What to do with the while loop and how to find even and odd numbers.

View Replies View Related

For Loop Involving Array

Jan 29, 2015

As a result I need to get 6 66 666 6666 66666, but I'm getting a mistake. Can anb explain what's wrong?

Java Code:

public static void main(String [] args)
{

int[] sixes = new int [6];
for (int i = 0; i < sixes.length; i++)
{
sixes[i] = i * 10 + 6;
System.out.print(sixes[i]);
}

} mh_sh_highlight_all('java');

View Replies View Related

If Statement Not Working?

May 5, 2014

I'm having a problem where an if statement isn't working. In the Person class boolean olderThan ignores my if statement so it always returns false and I just don't get why that's happening.

import java.util.Calendar;
public class Person {
private String name;
private MyDate birthday;
  public Person(String name, int pp, int kk, int vv) {
this.name = name;

[code].....

View Replies View Related

Boolean Statement Not Working

Apr 14, 2015

code=Java
import java.util.Random;
import java.util.Scanner;
public final class Derp {
public static int WIN, Tick;
public static Scanner Input = new Scanner(System.in);

[code]...

why this boolean statement isn't working correctly. It's not detecting that the WIN and Tick are the same and instead chooses to always run the second statement.

View Replies View Related

Why If Statement Isn't Working Correctly

Apr 23, 2015

I am building a program that when you enter 1. it allows you to setup an item. However running my code my second if statement runs through.

import java.util.Scanner;
public class InventorySystem {
public static void main(String [] args) {
Scanner input = new Scanner(System.in);
int count=0;
int inputEntered=0;
int numberOfItems=0;
double cost=0.00;
String item;
String description;
 
[code]...

View Replies View Related

If-else Statement Not Working - Syntax Error

Sep 14, 2014

My if else statement is not working...it keeps telling me that the else in the statement is a syntax error and that I should remove it. Whats wrong with it?
 
package Homework2;
import java.util.Scanner;
public class Homework2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Welcome to the Triangle Program.");
 
[Code] ....

View Replies View Related

Buffered Reader Statement Not Working

Mar 12, 2015

String name="admin";
String fpass="";
try {
BufferedReader in = new BufferedReader(new FileReader("D:Dairy MangamentNew1 Dairy ManagmentPassword.txt"));
fpass = in.readLine();
in.close();
} catch (Exception e) {e.printStackTrace();}

[Code] ....

Its not comparing the user name and password..

View Replies View Related

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

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

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

Why While Loop Isn't Working

Oct 29, 2014

working on a project but cant seem to get my while loop to restart i want to restart this guessing game if the user inputs y at the end otherwise it will end.

import java.util.Scanner;
import java.util.Random;
public class GuessingGame{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
String again = "y";
while(again=="y"){

[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

Why Do-while Loop Isn't Fully Working

Sep 23, 2014

I'm having trouble figuring out why my do-while loop isn't fully working. As you can see, it will loop for the first 2 values of i (1 and 2), but then after that if i doesn't fit in my if or if-else statements, the loop stops.

int iterationNum = 1;
int cycle = 0;
double denominator = 1.0;
double pi = 0.0;
double validPrint;
int n = 1;
do {
pi += (4.0 * Math.pow(-1.0, cycle))/denominator;

[code]....

View Replies View Related

Print Triangle - Loop Is Not Working

Jul 7, 2014

I am trying to make a program that prints triangle... and I did various test on each method to realise that the problem lies with this segment.When I call this method, nothing prints out, I figure there is something with the loop that I am not realizing.the loop is backwards because it's supposed to have the right side edge parralel (when I try to print it out the spaces do not appear, imagine the x are space...), so as each line is looped the # of spaces diminishes

xxxx*
xxx*x*
xx*xx*
x*xxx*
*****

public class test {
public static void main(String[] args){  
for (int countdown = 5; countdown <= 1; countdown = countdown--){
showNTimes(countdown, ' ');
showNTimes(5- countdown, '*');
System.out.println("");
}
}
public static void showNTimes ( int nbTimes, char carac ) {
for ( int i = 1 ; i <= nbTimes ; i = i + 1 ) {
System.out.print( carac );
}
}
}

View Replies View Related

Adding Stars After Each Item In The List - For Loop Isn't Working?

Feb 26, 2014

This is supposed to be a method that adds stars after each item in the list.

Java Code:

import java.util.ArrayList;
public class ClientProgram {
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<String>();
list.add("the");

[Code] ...

I'm guessing it's because list.size() changes, though but it should only find that value in the beginning, so it shouldn't be a problem?

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

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







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