Arrays And Number Generator - Determine And Print Largest And Smallest Values

Dec 4, 2014

/*
Purpose: To write the methods and the rest program. The program should fill a 4 X 4 2 dimensional array with random numbers between 100 and 200. The program should then determine and print the largest and smallest values within the array using two Methods Largest and Smallest. The program should then determine and print the number of values within the array that are even using a function called Even. The program should also enter a loop that will only terminate when the user inputs a -1 as a choice. The loop should continue to ask the user to guess a number that was randomly generated. The program should call the Findit function to determine if the number was in the array. The program should print out the values in the array when the user selects a -1 and then terminate.
*/

import java.util.Scanner;
import java.util.Random;
public class LNFI_2DArray
{
public static void main(String[] args) {
int guess;
int[] array = new int[4];

[Code] ....

I just had this code working, then all of a sudden i was hit with a 'keyboard leak' error code.

View Replies


ADVERTISEMENT

Determine If Lengths Of Three Strings Are In Order By Length / Smallest To Largest

Feb 18, 2015

Suppose s, t, and w are strings that have already been created inside main. Write a statement or statements, to be added to main, that will determine if the lengths of the three strings are in order by length, smallest to largest. That is, your code should determine if s is strictly shorter than t, and if t is strictly shorter than w. If these conditions hold your code should print (the boolean value) true. If not, your code should print false. (Strictly means: no ties)

View Replies View Related

No Compiler Errors / Finds Largest Number In Array But Not Finding Smallest

Oct 19, 2014

A java program to print 10 random numbers between 512 and 1024 and then finds the smallest and biggest numbers from the list using only one loop

class BSLab4d {
public static void main (String[] args){
int[] nums = new int[10];
int largest = nums[0];
int x = 0;
int smallest = nums[0];
int y = 0;
 
[code]....

View Replies View Related

Print 2 Largest Number In Array

Apr 1, 2014

Thought process : Sort the array and print the last 2 element of any given array.

Note /| Should not use any inbuilt Array.sort()

Java Code:

//Write a code to print the 2 largest numbers from the given Array {2,8,10,5,9}

package arrays;
public class biggest2numbers {
public static void main(String[] args) {
int[] A = {2,8,10,5,9};
//Declaring 2 variable
int Max1,
Max2;

[Code] .....

View Replies View Related

Program Will Print Out Largest Number And Exit

Oct 1, 2014

Description of the program: read a sequence of positive integers from terminal. When user types

-1, the program will print out the largest number and exit.

Program mid.java
import java.util.Scanner;
public class test
{
public static int num;
public static void main (String[] args)
{
Scanner in = new Scanner(System.in);
num = in.nextInt();
int large = num;
while(num > 0);
{
if(0 > num && num > large)
large = num;
}
System.out.println("The largest number is : " + large);
}
}

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

Reverse Grades From Largest To Smallest And Corresponding Names

Jan 20, 2015

I want to reverse grades that i have put using JOptionPane from largest to smallest and the corresponding names..

import javax.swing.*;
import java.util.Arrays;
public class ArrayUtils {
public static void main (String[]args){
String length = JOptionPane.showInputDialog("Number of students");

[code]....

View Replies View Related

How To Use Selection Sort For Array From Smallest To Largest

Nov 19, 2014

I know it is possible to do this using the Array class but I don't want to use that. I am trying to use selection or bubble sort but I believe selection is what I want. This program asks the user to input 2 arrays with 10 integers each, sorts them from smallest to largest, then states whether they are the same or not. Comparing the two arrays.

import java.util.Scanner;
public class SetDifference
{
public static void main (String args[])
{
Scanner sc = new Scanner (System.in);
int array1[] = new int[10];
int array2[] = new int[10];

[Code] .....

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

Program To Display Both Largest And Smallest Of A Series Of 5 Integers

Apr 27, 2014

Here is a simple program on applets that is giving me a bit of headache since it cannot always display the two numbers that it is supposed to: the largest and smallest of the five input integers.....I cannot see where i went wrong, you can always create separately the HTML file to load the applet in an appletviewer of your won size.

*
23.6 (Largest and Smallest) Write an applet that reads five integers, determines which are the largest and smallest integers in the group and prints them. Draw the results on the applet.
*/
import java.awt.Graphics;
import javax.swing.JApplet;
import javax.swing.JOptionPane;

[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

Tic Tac Toe Game - Random Number Generator And Two Dimensional Arrays For Game Board

May 9, 2015

Im trying to make a tic tac toe game that you play against the computer using a random number generator and two dimensional arrays for the game board. Im not trying to make a GUI, the assignment is to have the board in the console, which I have done. I have run into a few problems with trying to get the computer player to correctly generate 2 integers and have those two integers be a place on the game board. Here is my code so far.

import java.util.Random;
import java.util.Scanner;
 public class TicTacToe {
 private static Scanner keyboard = new Scanner(System.in);
private static char[][] board = new char[3][3];
public static int row, col;
 
[Code] ....

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

Random Generator And 2D Arrays?

Sep 21, 2014

So im making this ghost game where i display an 8x8 filled with 0s and a randomly generator five 1s in there I can get it to display 0s and add 1s, however sometimes the 1s that are randomly generated sometimes go on the same spot making it look like there are only four 1s. How would i go about fixing that?

package Grade12;
 import java.util.Random;
 public class Ghost {
 public static void main(String[] args) {
 Random generator = new Random();
 int gameboard [][] = new int [8][8];
int randomx, randomy, counter = 0, sum = 0; 
for(int row = 0; row < 8; row++){
for(int col = 0; col < 8; col++){ 
(gameboard[row][col]) = 0;
 }

[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

How To Create Simple Random Number Generator For Number Between 1 -10

May 18, 2015

I am working on a little nothing project, but I wanted to create a random number generator for a silly game where the user guesses the number.I have used google, but they are using LOG statements, what it does.

View Replies View Related

Equivalent Arrays - Comparing 2 User Inputs To Determine If Same

Mar 4, 2015

I have been stuck on this for the past 2 hours, basically we have to compare user input, put user input into an array and compare for equivalency. An example of the program:

Array 1: 1 2 3 4 5 6 7 8
Array 2: 1 2 3 4 5 6 7 8
Array 3: 1 2 3 4 5 6 7 8 9
Array 4: 1 2 3 4 5 6 7 8

Array 1 & 2 are equal
Array 1 & 3 are not equal
Array 1 & 4 are not equal.

This cannot be done by importing Java.util.Array at all!! (my research only find this to compare arrays ) which is why I am having trouble starting off. My code thus far:

import java.util.Scanner;
public class Lab07b {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter Integer 1:");
int a = input.nextInt();

[Code] .....

View Replies View Related

Process Data And Determine Winners - Two Dimensional Arrays

Feb 4, 2015

The international Olympics Committee has asked you to write a program to process the data and determine the medal winners for the pairs figure skating. You will be given the following file: Pairs.txt

Which contains the data for each pair of skaters. The data consists of each skater's name, their country and the score from each of eight judges on the technical aspects and on the performance aspects. A typical record would be as follows:

Smith
Jones
Australia
5.0 4.9 5.1 5.2 5.0 5.1 5.2 4.8
4.3 4.7 4.8 4.9 4.6 4.8 4.9 4.5

The final score for each skater is the sum of the average of the two categories of score. Design a class to hold the above data and the final score. Read the data in from the file and calculate the final score for each pair. Sort the array of objects , and display the results on the screen in order, giving special prominence to the medal winners.

Here is my CLass:

public class Skaters {
private String name1;
private String name2;
private String country;
private double [] arrTech = new double [8];
private double [] arrArt = new double [8];
private double score;

[code]...

how do i print my 2 arrays using the file? i got the name1, name2 and counntry to print but im stuck on printing the scores that are stored in the arrays. Also, i have to print the average for each array. one is for techniques and the other one is artistic. as you can see i already wrote the code for it but im stuck in printing it.

View Replies View Related

Index Of Largest Number In A Integer?

Jul 21, 2014

This is my program

public static void main(String args[]) {
Scanner in=new Scanner(System.in);
System.out.println("Enter the Total Number of Integers:");
int totalInteger=in.nextByte();
long largest=0;
for(int i=1;i<=totalInteger;i++) {
System.out.println("Enter Integer-"+i+":");

[code]...

I want to get Index of that particular number in which Value is largest.

What I need to change in my program?

View Replies View Related

ArrayList - Scan Array For Largest Number

Mar 24, 2014

I need to create a program that uses ArrayList to store integers the user inputs, then scan the array for the largest number. I would also like the user to be able to exit this loop if the number 0 is entered.

As you can see below, I'm not sure how to correctly exit the do-while loop. I found this on another forum, but it does not work.

Java Code:

import java.util.*;
public class array {
public static void main(String [] args){
ArrayList<Integer> list = new ArrayList<Integer>();

[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

Creating Java Program That Prints The Smallest Number

May 9, 2015

Here is my code :

import java.util.Scanner; 
public class smallestnumber
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in); 
int smallest =0;
int number;

[Code]...

here is the output of my code:

Enter the number
88
Enter the number
8
Enter the number
6
Enter the number
55

[Code]...

Why is it printing 0 instead of 1?

View Replies View Related

Random Number Generator Then Summing

Aug 29, 2014

I am brand new to programming and java. I decided I wanted to learn programming so now I'm in a class. I am into my second week and my assignment is to generate 100, 3 digit numbers then add them together. I understand how vast java is, but as of right now we have only studied if/else/switch statements, I was able to get the 100, 3 digit numbers generated, but I cannot add then together.

import java.util.Random;
import java.util.Math;
public class ThreeDigitGenerator {
public static void main(String[] args) {
int sum = 0;

[Code] ....

View Replies View Related

Prime Number Generator - Range From 0 To 199

Feb 5, 2015

public class printprimes2{
 public static void main(String[] args){
  for( int i = 1 ; i <=199 ; i++ ) //iterate 1 - 199; 2 is prime {
for ( int j = 2 ; j < i ; j++ ) //iterate 2 - potential composite EXCLUSIVELY; every number can be divided by one and itself

[Code] ....

It doesn't print only prime numbers but all numbers that range from 0 to 199. What do you think I am doing wrong?

View Replies View Related

Random Number Generator Error

Dec 1, 2014

I am new at coding and I can't seem to figure out why my random number generator (numGen) won't let me compile. this is the game class to a game i'm making called Bagels. its very similar to the game mastermind in the sense that you have to try to guess a three digit number and the computer will return feedback giving you clues that will guess the number.

import java.util.*;
import java.io.*; 
public class BaglesGame {
public static numGen() {
Random Rainbow = new Random ();
firstDigit = "" + Rainbow.nexInt(10);
 
[Code] .....

View Replies View Related







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