Numbers Divisible By 6 - Code Is Giving Different Result Then Expected

Aug 22, 2014

I am having problems with writing a simple program to see if a number is divisible by 6.

public void run() {
println("This program will display all numbers divisible by");
println(" 6 between 1 and 100.");
int x =1;
boolean divide =(x%6==0);

[Code] ....

It is telling that every number is not divisable by 6?

View Replies


ADVERTISEMENT

Display Two Numbers / Integer Code And Computed Result To Screen

Oct 26, 2014

Write a program that will read two numbers and an integer code from the keyboard. The value of the integer code should 1, 2, 3, 4. If the value of the code is 1, compute the sum of the two numbers. If the code is 2, compute the difference (first number minus second). If the code is 3, compute the product of the two numbers. If the code is 4, and the second number is zero, compute the quotient (first divided by second). If the code is not equal to 1,2,3,4, display an error message. The program is then to display two numbers, the integer code and the computed result to the screen

here is the code that I have so far:

public static void main(String[] args) {
Scanner read = new Scanner (System.in);
int num1, num2, code, sum;
System.out.println("Please enter a number");
num1 = read.nextInt();

[Code] .....

View Replies View Related

Output Is Not Giving Proper Result - Semantic Error?

Oct 5, 2014

why the output is not giving the proper result? Is this a semantic error?

public class Programming1Practice {
/* testing out instantiation and object oriented programming */
public static class staticValues {

[Code]....

View Replies View Related

Finding Longest Increasing Sequence Not Giving Proper Result

Jan 28, 2015

Okay so I need to be able to read a file and then be able to find the longest sequence of increasing numbers.

So if the file was this, (this is Ass1Q2_test4.txt)

97 47 56 36 60 31 57 54 12 55
35 57 41 13 82 80 71 93 31 62
89 36 98 75 91 46 95 53 37 99
25 45 26 17 15 82 80 73 96 17
75 22 63 96 96 36 64 31 99 86
12 80 42 74 54 14 93 17 14 55
14 15 20 71 34 50 22 60 32 41
90 69 44 52 54 73 20 12 55 52
39 33 25 31 76 45 44 84 90 52
94 35 55 24 41 63 87 93 79 24

the output should be,

(5,0) with cost 12
(6,0) with cost 14
(6,1) with cost 15
(6,2) with cost 20
(7,2) with cost 44
(7,3) with cost 52
(7,4) with cost 54
(6,3) with cost 71
(5,3) with cost 74
(4,3) with cost 96

Greatest path is of length 10.

Now, the code that I have works, kind of. Instead of recurring several times at each point, it only recurs once.

So say I'm looking at (1,1). With (1,1) being 57. The area around it looks like this.

97 47 56
35 57 41
89 36 98

Now when I look at it, there are several paths it can take. It can go 57, 97 or 57, 89 or 57, 98. However, I'm pretty sure that it just uses the first one that corresponds with the first if statement that is valid. So I start checking north of the value, then northeast, then east, then southeast, which at southeast is where I find my first greater than value. After it finds it's first valid number, it then continues from that number, instead of checking if there are other longer paths stemming from the original value.

In conjunction with that, you can see that the printout just returns all paths from each value. Which isn't what I want. I need a way to store the longest current path, then check each path after to see if it's longer. If it is, it's replaced, if not, it stays the same.

I've also attached Ass1Q2_test4.txt

import java.util.*;
import java.io.*;
public class MaxIncreasingSub {

[Code].....

View Replies View Related

Simple Program Giving Negative Result For Amount Of Calculations Done

Mar 5, 2014

Why this extremely simple program seems to be giving me a negative value for amount of calculations done within one minute ( Just using it as a bit of fun to see how different computers in the office perform).

Java Code:

class Benchmark {
public static void main(String[] args) {
long endTime = System.currentTimeMillis() + 60000;
int count = 0;
for (int i = 0; System.currentTimeMillis() < endTime; i++) {
double x = Math.sqrt(System.currentTimeMillis());
count = i;
}
System.out.print(count + " calculations per minute");
}
} mh_sh_highlight_all('java');

I am getting results between -2.1billion and -3.4billion which to me would make sense since they are not the best computers in the world but I would be expecting a positive value?

View Replies View Related

Finding Divisible Numbers And Replace With String

Jul 13, 2014

My interest in Java leads me to try and print numbers from 1-100. The output should show all numbers from 1-100 and each number that is divisible by by 13 should be replaced with a string "Fuzzy".

public class Fuzzy {
public static void main (String[]args){
for(int i = 0; i < 100; i++)
if(i % 13==0)
System.out.print(i + "fuzzy");
}
}

View Replies View Related

Average Program - Divisible Numbers Not Calculating Correctly

May 21, 2015

For some reason, the averages aren't calculating correctly. I'm aware I need to convert to double if I'm dividing by an odd amount but that itself isn't the issue. It's just simple easy divisible numbers that are not being calculated correctly. For instance, (10 + 10 + 10 + 50) / 4 = should be 2 but I get 10.

Here is the code:

import java.util.Scanner;
public class Avg {
public static void main(String[] args){
Scanner inputGains = new Scanner(System.in);
int userInput = inputGains.nextInt();

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Code Keeps Saying Identifier Expected

Feb 27, 2015

my code keeps saying identifier expected Here's my code

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

[code]....

View Replies View Related

If Number Is Even - Divisible 3 Or Divisible By 4

Apr 7, 2014

I have to make a program that determines whether an integer put in by the user is odd, divisble by 3 or divisble by 4..

import java.text.DecimalFormat;
import java.util.Scanner;
public class numbers {
public static void main (String[] args)

[Code] ....

I'm getting the error that div3 hasn't been initialized ... How do I even implement code to determine whether the number is divisible by 4 or 3?

View Replies View Related

Rectangle With Numbers - Result Type Is Void

Jun 12, 2014

I want to write a method which would give us a rectangle with numbers. The input is an integer which represents the length of a line in rectangle and the result type is void. The example for n=4 is:

3210
0321
1032
2103

View Replies View Related

Mode Methods - Numbers Repeated In Result

Apr 12, 2015

I got this code with mode methods. The results is not exactly what I want.
 
Code:
import java.util.ArrayList; 
import java.util.Arrays; 
import java.util.List; 
import java.util.Random; 
  import java.util.*; 
 
public class ProcessMarks { 
    private static final int NMARKS = 125; 

[Code] ...

Result (it's repeat number):
*Mode is = 53
*Mode is = 53
*Mode is = 53
*Mode is = 53
*Mode is = 53
*Mode is = 62
*Mode is = 62
*Mode is = 62
*Mode is = 62
*Mode is = 62
*Mode is = 67
*Mode is = 67
*Mode is = 67
*Mode is = 67
*Mode is = 67
*Mode is = 77
*Mode is = 77
*Mode is = 77
*Mode is = 77
*Mode is = 77
*Mode is = 78
*Mode is = 78
*Mode is = 78
*Mode is = 78
*Mode is = 78
*Mode is = 85
*Mode is = 85
*Mode is = 85
*Mode is = 85
*Mode is = 85
 
Result that i want it to be (number appear only once):

*Mode = 53, 62, 67, 77, 78, 85

or

*Mode is = 53
*Mode is = 62
*Mode is = 67
*Mode is = 77
*Mode is = 78
*Mode is = 85

View Replies View Related

Translate Morse Code And Then Display Result

Jul 24, 2014

I'm currently working on a program that is supposed to translate morse code and then display the result and I'm stuck, my program has tons of errors when I try to compile.

public class Assignment10
{
public static void main ( String [] args )
{
String str = Input.getString("Please type in a word");
char [] letters = {'a','b','c','d','e','f','g',

[Code] .....

View Replies View Related

Modify Code That Converts Binary Code To Decimal Numbers

Aug 29, 2014

The code here I have works fine if I just want to ask the user to enter four digits: //java application that asks user to input binary numbers(1 or 0) and convert them to decimal numbers import java.util.Scanner; //program uses class scanner public class binarynumber{
 
//main method that executes the java application
public static void main(String args[]){
//declares variables
 
int digit;
int base=2;
int degree;
double decimal;
int binary_zero=0;
int binary_one=1;
//create scanner for object input

[code]....

The thing is, I want the java application to input more than four digits for the user and I want it to loop it manytimes f until the user ask it to stop.

View Replies View Related

Double RelativeFrequency Value Which Does Calculation / End Result Is Number With Lots Of Decimal Numbers

Nov 24, 2014

for (int i = 0; i < letters.length; i++) {
double relativeFreq = (onesAverage()/letters[i]);
char a = characters.charAt(i);
double j = score[i];
System.out.printf();//ToDo

Above is my current code. Basically- There is a string called characters of length 26 (1 char for each letter in alphabet), a double relativeFrequency value which does a calculation and the end result is a number with lots of decimal numbers. The score array has set double values within the array.

What I want to do is create a print f statement where I print out each of the values I initialized above WITH specific amounts of spaces in between. So it should be in this order:

a (spaces) j (spaces) relativeFreq (newLine).

Between J and relativeFreq there should be 4 spaces, however if the value in relativeFreq is greater than 10 (it won't be greater than 100)- then there should be 3 spaces. Everytime I try to create a printf statement my code ends up crooked for some of the values.

for (int i = 0; i < letters.length; i++) {
double relativeFreq = (onesAverage()/letters[i]);
char a = characters.charAt(i);
double j = score[i];
System.out.printf("%c %.4s %.4s%n",a, j, relativeFreq);

View Replies View Related

Find Number Of And Sum Of All Integers Greater Than 100 And Less Than 200 Divisible By 7

Oct 30, 2014

 Write a program to find the number of and sum of all integers greater than 100 and less than 200 that are divisible by 7.

View Replies View Related

Code Allows To Enter Negative Numbers -1

Apr 4, 2015

double CashInsert = Double.parseDouble(CashAmounttxt.getText());
System.out.println("Cash Received: " + "£" + CashInsert);
if (CashInsert<=0 &&(CashInsert <TotalPrice)){
ChangeLeft = CashInsert - TotalPrice;
System.out.println("Total: £" + TotalPrice);
System.out.println("Change Due: " + "£" + ChangeLeft);}
else {
System.out.println("Insuffient funds, please enter £"+ TotalPrice +" or More");}
}

#################################################

Cash Received: £-1.0
Total: £4.85
Change Due: £-5.85

It allows me to enter -1 I've already coded it so the person cannot enter less but -1 works.

View Replies View Related

Filters Java Programming - Determine If Integer Is Not Divisible By Some Value

Apr 10, 2014

I am new to java and do not understand how to use filters very well. I need to write a code that determines if an integer is not divisible by some value. A filter also contains an upstream filter so that this filter can be part of a chain of filters.

View Replies View Related

Code Converts A String That Has All Numbers Into Integer

May 8, 2015

I am trying to code using error handling and I am a bit confused on how to go about doing it correctly. My code converts a string that has all numbers into an integer and the error handling should recognize that if it isn't a proper number and ask the user to try again or enter 'q' to quit.Do I place a throw new exception in the try block and put conditionals like if charAt(i) is some letter or a symbol then throw new exception?

Java Code:

import java.util.Scanner;
public class practice {
public static void main(String[] args) {
Integer finalValue = null;
boolean validValue = false;
Scanner scan = new Scanner(System.in);
int result = 0;

[code]....

View Replies View Related

Sieve Code To Find Prime Numbers

Jan 16, 2015

I am doing a sieve code to find prime numbers.

public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.println(" Enter the maximum number ");
int maxNumber = scanner.nextInt();
int[]numberList = createList (maxNumber);

[code]....

I have a problem with the output. It only get as far as marking the multiples of 2. It does not mark the multiples of 3 and so on.Example output: If the range is from 2 to 15 the output is :2, 3, 0, 5, 0, 7, 0, 9, 0, 11, 0, 13, 0, 15 note: 0 means its marked.As you can see it only marks multiples of 2 but it does not mark multiples of 3 above. I think the problem lies in the for loop inside my main method, because the index does not increment.

View Replies View Related

Simple Switch Code For Random Numbers

Feb 10, 2015

I am doing a project to generate three names of fruits. When I take out my switch code the numbers generate randomly, but when I added the switch code back I kept getting three instances of "Bars" as if the random numbers all became 5.

public static void main(String[] args)
{
System.out.println("Enter the amount of money you would like to gamble.");
Scanner keyboard = new Scanner(System.in);
int num1;
int num2;
int num3;
int money;
money = keyboard.nextInt();

[code]...

View Replies View Related

Jar Not Working As Expected

Feb 2, 2014

the problem which im facing when executing jar file is it is not working same as when i run file using the IDE.When run jar file, it won't open the new frame even the user and pass combination correct.But when i'm compiling using the IDE, it works as charm. The main menu popped up after i logged in.I've tried Clean and Build and it's not working too.

View Replies View Related

Why Java Is Giving Error For Symbol

Sep 28, 2014

I am having trouble figuring out why java is giving me an error for the symbols. I will post the errors below the code.

Java Code: import java.util.Scanner;
public class ShelbyHarms_3_02 {
public static void main(String[] args) {
Scanner console = new Scanner(System.in);

[code]....

View Replies View Related

Output Giving Question Marks?

Feb 6, 2015

I am testing a code given by my lecturer and the output it gives me are all question marks? Heres the code:

package assignment;
import java.util.Random;
public class DeckOfCards { // begin DeckOfCards data type

// playing cards of deck of cards
private PlayingCard[] deck;

[code]....

View Replies View Related

Window Should Pop Up Giving Properties Of Javac

Feb 20, 2014

I have just tried to learn java this week [COLOR="#000000"]and I am being held back by this once installed java jdk I nav to the java file and the bin file and then the javac file to find that the below tab does not exist

A new window should pop up giving the properties of the javac, there should be an attribute called Location..I can see the location option in my documents but in no other folder

View Replies View Related

Infile Output - Only Giving One Name Two Times

May 7, 2014

I am having issues with the first part of my program. When I got to display what is in the textfile, it only gives me one name two times. I cannot figure out what to do with my outer loop in order for it to read and output the entire data file.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import java.util.Scanner;
import java.io.*;
import java.text.*;
import java.math.*;
import java.util.StringTokenizer;

[Code] ....

View Replies View Related

What Is Identifier Expected Error

Jan 6, 2006

When do you get the error <identifier> expected? I've written a small application where input is accepted by a textfield and based on some condition a dialog should be displayed saying "invalid i/p". But am not able to correct ths particular error ....

View Replies View Related







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