Find Average Of Integers That Are Inputted

Jul 26, 2014

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

[code]...

find the average of the integers that are input but can't manage to solve the problem.

View Replies


ADVERTISEMENT

Print Inputted Data - Name / Score And Average Using Array

Aug 22, 2014

Conditions : Need to print all the inputted data(name,score) and the average.

import java.util.Scanner;
public class Case2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[] score = new int[5];
String[] name = new String[5];
int ave = 0;

[Code] .....

View Replies View Related

Find Weighted Average Of Four Test Scores

Apr 17, 2015

Write a program in JAVA in response to the following prompt:

Design a GUI program to find the weighted average of four test scores. The four test scores and their respective weights are given in the following format:

testscore1 weight1
...

For example, the sample data is as follows:

75 0.20
95 0.35
85 0.15
65 0.30

The user is supposed to enter the data and press a Calculate button. The program must display the weighted average.

Here is what I have written:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class weightedaverage2 extends JFrame {
private JLabel Score1L,Score2L,Score3L,Score4L;

[Code] .....

View Replies View Related

Find The Column With Highest Average Number

Feb 14, 2015

code a 10 * 10 matrix, with random numbers from 1 to 100,

i) Find the most repeated number.
ii) Use the Binary Sort, to sort the matrix in ascending order.
iii) Find the Column, with the highest average number.

View Replies View Related

Find Number And Sum Of All Integers

Oct 29, 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

Find Both Largest And Smallest Of Several Integers

Apr 9, 2015

Write a program that finds both the largest and smallest of several integers. T. For example, a program that determines the winner and loser of a sales contest would input the number of units sold by each salesperson. The salesperson who sells the most units wins the contest; the salesperson who sells the least units loses the contest. Write a pseudocode program, then a Java program that inputs a series of 10 integers and determines and prints the largest integer and the smallest integer. Your program should use at least the following four variables: counter, number , largest and smallest. After i run the code i just get the largest input without the smallest .

This is my code :

import java.util.Scanner; // program uses scanner
// main Class begins
public class Largest12
{
public static void main(String[] args) //main method begins
{
//Initial variables
int counter = 0; // initiate counter
int number=0 ;

[Code] ....

View Replies View Related

Program That Find Minimum Value In Array Of Integers

Feb 3, 2014

I'm required to create a program that finds the minimum value in an Array of integers.

Here is my approach :

public class Person {
public static void main(String [ ] args){
int theArray[]=new int [10];
int result = 0;
for (int i:theArray){
if (i < Integer.MAX_VALUE)

[Code]...

I can't really progress from this position. I keep getting told to change the return type to int on main method, then when i do it says change it to void..

View Replies View Related

Java - Find Number In Given Array Of Integers

May 2, 2014

I wrote this simple piece of code to find the number in the given array of Integers. The program works fine although it shows a couple of errors when i modify it a little bit.

public class DemoLabel{
public static void main(String [] args){
int[][] arrofInts={
{32,45,67,87},
{23,44,55,66},
{12,47,87,56},
{23,44,12,78}

[Code] .....

In the disp() method,Suppose i only want to pass two arguments i.e disp(i,j) given that searchFor variable is visible in the entire class but when i use disp(i,j) i get the following error

DemoLabel.java:38: error: cannot find symbol System.out.println("The number "+searchFor+" is at the location"+i+" , "+j);
^
symbol: variable searchFor
location: class DemoLabel

So i decided to declare the

int searchFor
as
public int searchFor

But the compiler threw another error saying that it was a Illegal start of expression

Also,when i add a SOP line after the label search: it shows the error

DemoLabel.java:25: error: undefined label: search
continue search;
^

Although i got the program to work it would be useful if i could understand why it doesn't work with the modifications.

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

Loop / Boolean - Find Greatest Common Divisor Of Two Integers

Sep 25, 2014

In attempting to find the greatest common divisor (gcd) of two integers, n1 and n2, whereas k is a possible gcd and gcd is initialized to 1, the following code has been entered:

for (int k = 2; k <= n1 && k <= n2; k++) {
if ( n1 % 2 == 0 && n2 % 2 == 0)
gcd= k;
}

When asked to change the previous line of code to this:

for (int k = 2; k <= n1 / 2 && k < n2 / 2; k++){

the questions states this revision is wrong and to find the reason.....well, I've changed it, entered "3" (per the answer key) for n1 and n2....

now I can see logically where k (2 in this example) is not <= n1/2, which is 3/2 or 1, since we're dealing w/integers, yet when I compile and run, my answer is indeed, gcd = 1. However, since this is a Boolean expression where && is being used, since the first portion evaluates to "false", the 2nd portion isn't executed and thus my result of 1?...... loops are throwing me for one, for sure....

View Replies View Related

Why Program Does Not Display Anything When Choices Are Inputted

Feb 28, 2014

I am experimenting with messages in JOptionPane and I was wondering why this program does not display anything when the choices are inputted.

*note: I tried putting "JOptionPane.showMessageDialog(null, "This is an information message", "Information", JOptionPane.INFORMATION_MESSAGE);" after the "int i = 0;" and then the messages displayed.

Scanner scan = new Scanner(System.in);
int i = 0;
while (i != 6)
{
System.out.println("1. Information message");
System.out.println("2. Error message");
System.out.println("3. Question message");
System.out.println("4. Plain message");
System.out.println("5. Warning message");

[code]....

View Replies View Related

Print List Of Jobs That Correspond With Inputted Day

Oct 21, 2014

I'm having some trouble with my project. I have filled the getters using an array and what I now need to do is get the user to type in a day and print the corresponding getters to the lines the day is on in my text file.

{
File file = new File("DailyJobs.txt");
Job newJob = new Job();
try (Scanner scanner = new Scanner(file);)/>
{
while(scanner.hasNextLine()) {
String line = scanner.nextLine();

[Code] ....

This is what I've attempted in terms of entering the day. It recognises the number of lines that has the inputted day but prints out only the very last job ID in the text file.

90301,14304,ITGURU,11/11/2014,Tuesday,735.75,1204,1205
90302,14314,ROK5TR,12/11/2014,Wednesday,335.75,1205
90303,14318,HRTBRK,13/11/2014,Thursday,125.5,1200
90304,14310,EVOH8R,14/11/2014,Friday,1207.95,1211
90305,14300,G4MER,11/11/2014,Tuesday,500,1204,1202

[Code] ....

This is the text file, the first number on each line is the Job ID and always prints the last line regardless of the day I enter.

View Replies View Related

Nested For Loops - Determine If Inputted Integer Is Even Or Odd

Sep 29, 2014

So I cant figure out why my output for my for loop isn't working properly. So the output for the square comes out right but the for loop isn't working properly for the H. I have tried to figure it out and it should go to the next line but its not.

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

[Code] ....

Output

Enter a positive odd integer: 5

Square:
*****
* *
* *
* *
*****

H:
* *

View Replies View Related

Constructors - How To Put 3 Values Of Each Variable Without Replacing Last Inputted One

Oct 2, 2014

Java Code:

public class Puppy{
int puppyAge;
public Puppy(String name){
// This constructor has one parameter, name.
System.out.println("Passed Name is :" + name );
}
public void setAge( int age ){
puppyAge = age;

[Code] ....

How do I put 3 values of the each variable without replacing the last inputted one?

Like when I input "Tommy" and input another name "Gerald", "Tommy" won't be replaced by "Gerald" when I input again.

View Replies View Related

Change A String Using Specialized Codes That Are Inputted

Feb 10, 2015

In this code, I have to do a series of tasks to change a String using specialized codes that are inputted. The one that I am having trouble with is as follows:

MC-SLXD: Circulates the sub-string in position S with a length of L, rotate the string X characters over in the direction of D. All the arguments (S,L,X and D will be one character in length. The direction will be either L or R for Left or Right.Example: MC-332R/COMPUTER = COPUMTER.

View Replies View Related

Counter Set Up For 20 People But Only Counts 19 If Error Inputted In GenreType

Oct 15, 2014

This is a piece of a program I am trying to write,my only problem is when an incorrect input is entered in "genreType" it still counts as a loop and therefore I do not end up with 20 results I am looking for..I have tried multiple different ways but nothing seems to work for me.

package assignment_1;
import javax.swing.*;
public class Assignment_1 { 
public static void main(String[] args) {
int rockCounter=0;
int popCounter= 0;
int danceCounter= 0

[Code] ....

View Replies View Related

How To Make A Program That Determines The Highest Value Out Of Inputted Numbers

Sep 14, 2014

how to make a program that determines the highest value out of the inputted numbers.

View Replies View Related

Change Specific Lines In Text Inputted From A File

Nov 29, 2014

I can't seem to understand how to change certain line of text, inputted from a file. For this I really don't know where to begin. I have got the input from the file. But I want to change like very other line in the file. Can't seem to understand how this could be done. Is there away to access specific lines from the file and edit them? So far, i have this:

import java.util.*;
import java.io.*;
public class ChangeEveryOtherLine {
public static void main(String[] args){
//Constructing file object representing input file
File inputFile = new File("input.txt");

[Code] .....

View Replies View Related

Translate User Inputted Sentence Into MorseCode - No Output?

Feb 19, 2014

The purpose of this program is to translate a user inputed sentence into morseCode. It seems like everything is right to me, but I'm simply not getting output! What am I doing wrong, or what should I add/change?

Here is the main class:

public class MorseCode
{
public static String myInput;
public static String[] myMorse;
public static String myUserInput;
public static char[] myAlph = {'A','B','C','D','E','F','G','H','I','J','K','L','M',
'N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
public MorseCode()

[Code] ....

View Replies View Related

Numbers Inputted By User And Sorting Them Out In Ascending Order

Nov 12, 2014

I am writing a program that is supposed to take 3 numbers inputted by the user and sorting them out in an ascending order. I believe my code is correct but can't figure out why the program isn't behaving as expected.

import java.util.*; //Required to use the scanner console
public class Week3_Programming_Problem
{
static Scanner console = new Scanner(System.in); //Allows for user input

public static void main(String[] args)

[code]....

View Replies View Related

Code Which Catches Exception When Mismatch Variable Inputted

Feb 27, 2015

I am trying my code which catches exception when mismatch variable is inputed as i read it with Scanner. It seems right for me but whenever i run it, it keeps leaking memory or something like that

Code :

import java.util.*;
public class Exercise10_1 {
static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
boolean exception;
do

[Code] .....

View Replies View Related

Subtract One User Inputted Integer From Another - Bad Operand Types

Mar 6, 2014

I've been working on this problem for a while now and continue to get an error when I try to subtract one user inputted integer from another. It seems to compile fine for adding, dividing, and multiplying. Why it might be making that error and how to resolve it? (As an aside, I have no idea if I did the whole program right but am just trying to figure out why a declared int would come back with an error it's a string.)

import java.util.Scanner;
public class Calculate2
{
public static void main(String[] args)
{
int firstInt;
int secondInt;
int choice;

[Code] ....

View Replies View Related

How To Get Index Of Array Based On User Inputted Account Number

Sep 25, 2014

In my account driver I am trying to get the user inputted account number to get the account by account number. In my code

System.out.println("Which Account number: "); int account = scan.nextInt();
ac.get(account-1);

This works if my accounts are numbered incrementally starting with one, I want it to match the inputted account number

System.out.println("Account number: "); int num = scan.nextInt();

I am thinking a for loop is probably needed. Here is my code:

public class AccountDriver {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
ArrayList<Account> ac = new ArrayList<>();
boolean more=true;
boolean again=false;

[code]....

View Replies View Related

Comparing Inputted Guess To Computer Random Sequence - Counter Not Working?

May 27, 2014

I have separated characters into an array that can be accessed from any method, however, when I try to compare the inputed guess to the computers random sequence, the counter always comes back as 0 (the comparison occurs in the checkColour method).

Java Code:

package mastermind;
import java.util.Scanner;
/**
* Program Description: play a game of mastermind versus the computer
*/
public class Mastermind {
private static int block1, block2, block3;
private static String blockColour1, blockColour2, blockColour3;

[Code] ....

The counter is called colourCorrect.. But I think the problem lies more in me converting the strings (input and computerGuess) into char arrays, as if I output the values at position in the array, I get numbers (but the numbers are not character values from the ascii table).

View Replies View Related

Program That Takes A User Inputted Number And Converts It To A Binary Number

May 5, 2014

trying to write a program that takes a user inputted number and converts it to a binary number.

Here's what I have:

package com.java2novice.algos;
import java.util.Scanner;
public class Converter {
static Scanner console = new Scanner(System.in);
public void printBinaryFormat(int number){
int binary = console.nextInt();

[Code]...

Bugs on:

Line 13
Line 17
Line 23

View Replies View Related

How To Get Data Button To Display User Inputted (numbers) To Data Label

May 25, 2014

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DisplayFinal_Panel extends JPanel {
private JLabel label1, label2, label3;
private JTextField box;

[code]....

I only want Listener 1 to work right now. Also, user input is in TextField.

View Replies View Related







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