Lottery - Sorting Numbers From Smallest To Biggest Without Repetition

Oct 29, 2014

I have problem with sorting my numbers from smallest to biggest and i need to not have repeating numbers, I am stuck. I tried using Arrays.sorts(lottery) but didn't work. and i don't know to but make the numbers not repeat in the same line.

package lottonumbers;

public class LottoNumbers {
public static void main(String[] args) {
int[] lottery = new int[6];
for (int numoftimes=0;numoftimes<5;numoftimes++){

[Code] ....

View Replies


ADVERTISEMENT

How To Find Biggest Two Int Numbers From Four

May 23, 2014

So, if you are a football/soccer fan, you know that in every FIFA World Cup you have 4 nations. From those 4, 2 will qualify to the Knockout stages.

Let's say, after all the group fixtures are played, the standings are as follows :

1. England - 6 points
2. Spain - 4 points
3. Brasil - 3 points
4. Germany - 1 point

I want to know how I can select ONLY England and Spain for the Knockout stage of the FIFA World Cup (The class I am working on).

View Replies View Related

Finding Fifty Biggest Numbers In The Array?

Feb 12, 2014

How to find fifty biggest numbers in the array?

View Replies View Related

Sorting ArrayList Of Geometric Objects By Area From Smallest To Largest

Mar 18, 2014

I have to create a method with the following header :

public static <E extends Comparable<E> > void sort ( ArrayList<E> list , int left, int right)

i also had to create a swap cells method and position of max integer method. and also had to read the preserved data file in with a scanner. I implemented the comparable interface I am having difficulty sorting my list by the area. It has to be in descending order.

Geometric Object class: since it has comparator also am interested if i need to change this?

CODE:

Driver:
public static void main(String[] args) throws IOException, ClassNotFoundException {
Circle c1 = new Circle (4, "red", false);
Circle c2 = new Circle (2, "blue", true);
Circle c3 = new Circle (10, "blue", true);
Rectangle r1 = new Rectangle (10, 6, "yellow", true);
Rectangle r2 = new Rectangle ( 5, 11, "green", true);
ArrayList <GeometricObject> list = new ArrayList();

[Code] ....

View Replies View Related

Sorting Arrays - Order From Greatest To Smallest Based On Frequency

Feb 12, 2014

These are all arraylists and not arrays

I have currently two arrays.

Java Code:

String[] chunks = {"a","b","c"};
int[] freq = {2,4,3}; mh_sh_highlight_all('java');

I am looking for a way to order these from greatest to smallest based on frequency.

The resulting arrays should be:

Java Code:

chunks = {"b","c","a"};
freq = {4,3,2}; mh_sh_highlight_all('java');

Because b is most frequent, and a is least frequent.

One way I can think of doing this is a two dimensional String array

Java Code: String[][] fullHold = {{"b","c","a"},{"4","3","2"}}; mh_sh_highlight_all('java');

Then sort based on the character values of the second row.

How can I sort a two dimensional array based on a single row (where it will rearrange the other rows in accordance).

View Replies View Related

Lottery Game Matching Numbers Error

Dec 11, 2014

import java.util.Scanner;
import java.util.Arrays;
public class LotteryTester {
public static void main(String[] args) { 
LotteryApplication lottery = new LotteryApplication();
int lotteryNumbersCount = lottery.getLotteryNumbers().length;
 
 [Code] ....

Everything works fine but when I run it the matching numbers tends to be off. For example I will type Enter in 1,1,1,1,1 for my 5 numbers. The lottery numbers will be 5,3,4,5,8 and it will say 1 number matched.

View Replies View Related

Make Program That Declare Largest And Smallest Out Of Three Numbers?

Jan 13, 2015

how can i make a program that declare the largest and smallest out of three numbers??

/*
* To change this license header, choose License Headers in Project Properties.
int a;
int b;
int c;

[Code]....

View Replies View Related

How To Find Smallest Number In A Group Of 3 Numbers Using While Loop

Mar 23, 2015

import java.util.Scanner;
public class AvgLrgSml{
public static void main(String[]args){
System.out.print("Hello there. Please enter any three numbers.");
Scanner keyboard = new Scanner(System.in);
double num1 = keyboard.nextDouble();
double num2 = keyboard.nextDouble();

[Code]...

View Replies View Related

Display Largest And Smallest Numbers In A Series Of 10 Inputs

Apr 15, 2014

I have to get the user to enter in 10 numbers and with those 10 numbers I have to find the total, average, smallest, largest numbers in the set the user inputs. I have the total and average already figured out but how would you go about trying to find the largest and smallest numbers within this set of code.

import java.util.*;
public class testhw7
{
public static void main (String [] args) {
Scannernumberin = new Scanner (System.in);
doublevalue[];
doubletotal;

[Code]...

View Replies View Related

User To Input 10 Numbers - Find Smallest Element In Array

Dec 2, 2014

I am trying to write a code that asks the user to input ten numbers and then finds and displays the smallest number out of the ones given. I am supposed to implement arrays into the program to do this. But the problem I have run into is that when I compile the code in jgrasp, I am given several error messages and I am not quite sure what I have done wrong. I'm assuming it is either a syntax or a logical error on my part but reading over the code I do not understand what is causing these errors.

This is the most current draft of my code:

import java.util.Scanner;
 public class Exercise7_9 {
public static void main(String[] args) {
double[] numbers = new double[10];
//Enter ten double numbers: Scanner(System.in)
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.println("Please enter ten numbers: ");

[Code] .... 
 
/* Sample Run:
Enter ten numbers: 1.9, 2.5, 3.7, 2, 1.5, 6, 3, 4, 5, 2
*/

And these are the exact error messages:

----jGRASP exec: javac -g Exercise7_9.java
Exercise7_9.java:35: error: '.class' expected
if (double m > list[i]) {
^
Exercise7_9.java:35: error: illegal start of expression
if (double m > list[i]) {

[Code] .....

View Replies View Related

Sorting A Text File With Strings And Numbers

Oct 16, 2014

how to sort my text file. So far I have been able to read the text file and print it back out, but I am unsure of how to go about sorting it. Must print the colors (in the order of the rainbow first) and if the colors are the same compare the size (bigger is more important)The values I have to sort are written as such in the text file:

blue 18
blue 10
red 27
yellow 4

public class Rainbow{
private String color;
private int size;
public Rainbow(String color, int size){
this.color = color;
this.size = size;

[code]....

I would know how to sort it if it was supposed to be alphabetical order or there were only numbers, but I can't seem to figure out how to sort it when there are strings and integers

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

Repetition - Print Number Of Occurrences

Apr 11, 2015

find whether it is a repetition free number or not. If it is, print the same number(x), else if it has repetitions then print the number of occurrences of the first repetitive digit you encounter.

View Replies View Related

Program Should Exit Repetition Loop And Compute And Display Average Of Valid Grades Entered

Oct 26, 2014

My homework assignment is: Using a do-while statement, write a Java program that continuously requests a grade to be entered. If the grade is less than 0 or greater than 100, your program should display an appropriate message informing the user that an invalid grade has been entered; a valid grade should be added to a total. When a grade of 999 is entered, the program should exit the repetition loop and compute and display the average of the valid grades entered. Run the program on your computer and verify the program using appropriate test data.

When I run it, I don't get the correct average. I know that i'm supposed to enter 999 to exit the loop and to display the average, but 999 is being added with the loop. I'm not sure how to make it not do that.

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

[code]....

View Replies View Related

Find Biggest Number From Array

Jun 26, 2014

I have 2 arrays in random order of 10 numbers.I need to find the biggest number from array A and B and then when its on a screen second thing is to multiply those numbers by 2.

import java.util.Random;
public class Projektas {
public static void main(String arng[]){
int i,j;
int A[] = new int [10];
int B[] = new int [10];;

[code]..

View Replies View Related

ArrayIndexOutOfBoundsException In Lottery Application

Jul 25, 2014

I have tried changing the bounds of the arrays but I still don't see where the exception is occurring or how to resolve this issue. Am I missing something blatantly obvious? Below are the two class files for the lottery application that I've been working on for a school assignment.

package com.lottery.test;
import com.lottery.Alarcon.*;
import java.util.Scanner;
public class PlayLottery {
public static void main(String [] args){
System.out.println("CIS-132. Lab 8. Problem #9 - Lottery. Faber Alarcon.");
Lottery lottery = new Lottery();

[Code] ....

I forgot to post the error message I was getting, here it is.

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
at com.lottery.Alarcon.Lottery.compareNumbers(Lottery.java:26)
at com.lottery.test.PlayLottery.main(PlayLottery.java:27)
Java Result: 1

View Replies View Related

Return Biggest Prime Factor Of Given Number

Sep 10, 2014

One of our assignments this week was to make a program that when given a number it will return the biggest prime factor of that number. So for example if the program is given the number 15, the output is 3.

144 gives you 3 also.
17 gives you 17
21 gives you 7.

Anyways, after some time trying out various things and combining stuff i googled with my textbook I somehow stumbled upon a code that works. But I cannot for the life of me understand how it works. I think it has something to do with the inner loop and the outer loop. But I feel like i cant go on without understanding how it works.

Here is the code:

public class BiggestFactor {
public static void main( String[] args ) {
int N;
N = StdIn.readInt();
int n = N;

[Code] .....

View Replies View Related

Find Biggest Corner Based On Number Zero

Apr 23, 2014

The program should find the biggest corner, based on the number zero.

A zero becomes a corner when there's the same amount of zeros under it, and left to it.

The program should print a message saying what's the biggest corner size.

Corner size is the number of zeros inside it.

Java Code:

import java.util.*;
class Corners
{
static Scanner reader=new Scanner(System.in);
static final int N=25;
static int corners(int a, int b, int[][] m)

[Code] ....

That's the output:

Java Code:

The BOX:
1 0 0 1 1 1 0 1 0 1 0 0 1 0 0 0 1 0 0 0 0 0 1 1 1
1 0 1 0 1 0 0 1 0 0 0 1 0 1 1 1 0 1 0 0 0 1 1 1 0
0 1 1 1 1 1 0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 1 0 0 0
0 1 0 1 0 1 1 1 1 1 1 0 0 0 1 1 0 0 1 1 0 1 0 0 1
0 0 1 1 0 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 1 0

[Code] ....

View Replies View Related

Java Application That Functions As Lottery Game

Nov 23, 2014

I am writing a java application that will function as a lottery game, using arrays it prompts the user to enter 5 digits and matches them against the random lottery numbers generated.

import java.util.Random;
import java.util.Scanner;
public class App {
public static void main(String[] args) {
int NUM_DIGITS = 5;

[Code] ....

View Replies View Related

Lottery Odds Program - Using For And While Loops With Calculations

Oct 13, 2014

/**
* In this program, use for and while loops with calculations to get the lottery odds.
*/
import java.util.Scanner;
import java.util.Random;
public class Lottery
{
public static void main (String []args)

[Code] .....

I need getting my numbers matching. When, I run the program each time no matter what number it keeps saying sorry no matches. However, I do need the program to have matches.

View Replies View Related

Lottery Game - Number Guessing Program

Sep 6, 2014

I wrote the following code for a lottery game. The problem comes when I run it. If one number of a 3 digit number matches, it's supposed to print "you win 1000" But regardless if a number matches or not, it says "sorry, no matches" ...

import java.util.Scanner;
public class Lottery {
public static void main(String[] args){
//generate lottery number
int lottery = (int)(Math.random() * 1000);
//Prompt the user to enter numbers
Scanner input = new Scanner (System.in);
System.out.print("Enter your numbers (3 digits): ");
int guess = input.nextInt();

[Code] .....

View Replies View Related

Java Program That Randomly Generates Five-digit Lottery Number And Prompts User For Input

Sep 25, 2014

Write a Java program that randomly generates a five-digit lottery number and prompts the user to enter a five-digit number. Each digit in the number is in the range between 0~9. The program should determine which prize the user wins according to the following rule:

• The user wins the first prize if the user input matches all five digits in the lottery number in exact order.
• The user wins the second prize if the user input matches any four digits in the lottery number in exact positions.
• The user wins the third prize if the user input matches any three digits in the lottery number in its exact position.
• The user wins the fourth prize if the user input matches any two digits in the lottery number in its exact position.
• The user wins the fifth prize if the user input matches any one digit in the lottery number in its exact position.

and here is my code. I cant get it to print the right statements.

import java.util.Scanner;
import java.util.Random;
class Hw5 {
static int getPrize(int g1, int g2, int g3, int g4, int g5,
int u1, int u2, int u3, int u4, int u5) {
//code for determining the prize comparing (g1, g2, g3, g4, g5) to (u1, u2, u3, u4, u5)
if (u1 == g1 && u2 == g2 && u3 == g3 && u4 == g4 && u5 == g5)

[code]....

View Replies View Related

Smallest Element In Array

Nov 7, 2014

I have been working on this assignment for a bit now. I seem to have most of the logic of it down, as far as I can tell, but I seem to have fallen into a bit of a brain lapse when it comes to invoking methods I've made in my main method. Here's the code:

package Module5;
import java.util.Scanner;
public class Exercise6Nine {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter 10 numbers.");
double[] numbers = new double[10];

[Code] .....

My question is, in my main method, I have code in there to attempt to call my method "min" from below, and to use the result of the min's calculations and print them via my main. Only, I can't seem to properly invoke the method from my main method!

Also, if you could check over my min method and see if anything blatantly wrong is there and let me know, that would be great.

Looking over my question, and it seems there is no EDIT button, but I may as well put the assignment parameters here, since I asked for double checking on my method. Write a method that finds the smallest element in an array of double values using the following header:

public static double min( double[ ] array )

Write a test program that prompts the user to enter 10 numbers, invokes this method to return the minimum value, and displays the minimum value.

View Replies View Related

Subset - Finding Smallest Possible Sum

Aug 2, 2014

I'm trying to apply a subset problem without using O(n^2) complexity. I need to find the smallest possible sum between 2 sets of 2 numbers in a lists so n1 + n2 = n3 + n4 = sum.

I have found solutions that all involve having the sum first and just finding the two pairs which involves using a hash table and then taking each number and subtracting it off the sum and looking for possible combinations.

How to do it if nothing but the list of numbers is given. So no sum and no hint of the pairs.

I put this in the Java section because I'm doing it in Java and there seems to be no generic algorithm/programming Topic area.

View Replies View Related

Find Largest And Smallest Value From Array

Nov 15, 2014

I am trying to display Largest value and Smallest value in an array but when I execute I get Largest value as 0.

Following is the code:

package simpleArray;
import javax.swing.JOptionPane;
class ArrayInteractive {
static String ch = "Q";
static boolean flag = true;
static String a[];

[code]....

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







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