Ask User To Store 10 Numbers In Array - Print In Order Entered And Reverse

Apr 15, 2014

Write a Java program that asks the user to store 10 numbers in an array. You should then print the array in the order entered and then print in reverse order. However, instead of putting all the information in the main, you should use a class called PrintIt. The PrintIt class should have an instance variable that is an array to hold the numbers. You should have a method that will print the array in the order entered. You will also need a method to print in reverse oder. Then create a tester class that asks the user to enter 10 numbers and puts them in an array.

So far I've got this.

public class printIt {
int i;
int [] numArr = new int [10];
public printIt () {
i = -1;

[Code] .....

Output:

Enter a number:

8
34

Forward:

8
34

Reverse:

34
8

end

what i want as an number is being able to print out 10 numbers but this only lets me do two numbers. Why is that so?

View Replies


ADVERTISEMENT

Store String Input In Array And Print In Reverse Order

Apr 5, 2014

I have a college question ask me to write a class StringRevert which does the following:

-prompting user for an interger n
-creating an array of n string
-repeatedly read character string from user input and store them in the array until end of array is reached or user input -quit(quit should not saved in array)
-print the string from array in reverse order, from last enter to first enter.
-assume user always supplie correct input

This is what I've done so far but how to get it working.

import java.util.Scanner;
public class StringRevert {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("enter value of n: ");
int n1 = in.nextInt();
String[] n = new String[n1];

[Code] ....

View Replies View Related

Floating Point Numbers - Print Contents Of Array In Reverse Order

Feb 27, 2014

I am trying to do this assignment but I can't get the needed output.

Create a program that asks the user how many floating point numbers he wants to give. After this the program asks the numbers, stores them in an array and prints the contents of the array in reverse order.

Program is written to a class called ReverseNumbers.

Example output

How many floating point numbers do you want to type: 5

Type in 1. number: 5,4
Type in 2. number: 6
Type in 3. number: 7,2
Type in 4. number: -5
Type in 5. number: 2

Given numbers in reverse order:

2.0
-5.0
7.2
6.0
5.4

Java Code:

import java.util.Scanner;
public class apples {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
double[] numbers;

[Code] .....

View Replies View Related

Order Of Numbers - Reverse Array Program

Apr 23, 2015

import java.util.Scanner;

public class ReverseOrder {
public static Scanner input = new Scanner(System.in);
public static void main(String[] args){
int[] numbers;
double[] reverse;

numbers = readArray();
reverse = reverseOrder(numbers);

[Code] ....

I have to write a program that takes an order of numbers and print the reverse order of those numbers.

the out put i receive is:

How many numbers do you want to enter?
4
Please enter 4 integers separated by a space:
1 2 3 4
Your numbers in reverse order are:[D@1f96302

View Replies View Related

How To Print TreeMap Values In Reverse Order

Apr 3, 2014

Below codes find the character frquency how to print this in reverse order using comparator or else

public static void main(String arr[]) {
String s="bebeao";
Map<Character,Integer> chars=new TreeMap<Character,Integer>();
for(int i=0;i<s.length();i++) {
char x=s.charAt(i);
Integer count=chars.get(x);
if(count==null)

[Code] .....

View Replies View Related

Print Greetings With Names In Reverse Order And With Punctuation

Apr 10, 2014

Write an application, HiFour that prompt for four names and then prints the greetings, but with the names in reverse order and with punctuation as shown in the example.

Enter four names: Alice Bob Carol Dave

Hi Dave, Carol, Bob, Alice.

View Replies View Related

Array In Reverse Order And Its Sum

Dec 3, 2014

This is how the for loop works for the row,right?

for(int i=array.length-1;i>=0;i--)
{
}

I want to know how the for loop works for the column?

View Replies View Related

Reverse Order Array Output

Oct 10, 2014

I'm trying to make this code's output display like a sentence, since right now it displays downward and doesn' look right.

public class ReverseOrder {
public static void main(String[] args) {
String phrase = "The rain in Spain falls mainly on the Plain";
char[] phraseArray;
phraseArray = phrase.toCharArray();
for(int i = phraseArray.length - 1; i >= 0; i--){
System.out.println(phraseArray[i]);
}
} // end main
} // end ReverseOrder class

View Replies View Related

Store Name SD Array And Display Room And Floor Number Whose Name Is Entered

Sep 12, 2014

I have to store the name SD array and display the room and floor no. whose name is entered but i am having a problem with the logic part. The answer is coming to be wrong

import java .io.*;
class hotel
{
public static void main()throws IOException {
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(read);
String ar[][] = new String[5][10];

[Code] ....

View Replies View Related

Swing/AWT/SWT :: GUI To Add A List Of Numbers Entered By The User

May 9, 2014

I have a GUI with a textArea for the user to input numbers, a button which should "listen" for those numbers, and then a textField to display the sum. I have my code working for user input of one number; but I'm at a loss as to what sort of loop I need to create to get it to read each line of input. I wasn't sure whether to put this in the beginner forum or here, because I am definitely a beginner.

So my code thus far that works with one input:

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

[Code] ....

View Replies View Related

Math On Three Numbers - Get Average / Sum And Number Entered By User

Feb 25, 2015

Java program : For this assignment you are going to write code for the following class:

MathOnThreeNumbers

Here are the specifications of class MathOnThreeNumbers:

Methods of class MathOnThreeNumbers:

1. inputThreeNumbers
2. getAverage
3. getSum
4. getNumberOne
5. getNumberTwo
6. getNumberThree

Constructor of class MathOnThreeNumbers

write a constructor that initializes the first, second, and three numbers to 1, 2, and 3 respectively.

Specs for the methods methods:

1.
name: inputThreeNumbers
accessibilty: public
arguments: none
what it does: asks the user for three numbers of type double

2.
name: getAverage
accessibilty: public
arguments: none
what it does: returns average of the three numbers

3.
name: getSum
accessibilty: public
arguments: none
what it does: returns sum of the three numbers

4.
name: getNumberOne
accessibilty: public
arguments: none
what it does: returns the first number entered by the user

5.
name: getNumberTwo
accessibilty: public
arguments: none
what it does: returns the second number entered by the user

6.
name: getNumberThree
accessibilty: public
arguments: none
what it does: returns the third number entered by the user

Here is an example of how the class MathOnThreeNumbers works. The following code produces the output displayed after the code.

MathOnThreeNumbers mm = new MathOnThreeNumbers();
System.out.println("first: " + mm.getNumberOne());
System.out.println("second: " + mm.getNumberTwo());
System.out.println("third: " + mm.getNumberThree());
mm.inputThreeNumbers();

[Code] .....

View Replies View Related

Perform Mathematical Calculation Between Two Numbers Entered By User

Feb 16, 2015

I need to write a Java program to perform a mathematical calculation between two numbers entered by the user. User has to choose the mathematical operation and input it and then when the user enters 2 numbers, he gets the answer. When user enters any other character other than *, /, + and - he should be able to exit. Perform calculation between numbers should be until user decided to exit from the program. My code is below, calculation part goes well, but can't get it exit when user enter any other character.. How to fix it?

import java.io.*; 
public class q11

public static void main(String[]args)throws IOException
{
InputStreamReader ISR=new InputStreamReader(System.in);
BufferedReader BR=new BufferedReader(ISR);
while(true){
System.out.println("Enter..");
System.out.println("* : For multiplication");

[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

Program That Takes User Odd Number And Print Prime Numbers Lower Than User Input

Nov 4, 2014

I have been struggling with this program for weeks. This program is supposed to take a user's inputted odd number and then print out all prime numbers lower than that number.

public class PrimeNumber
{
Scanner scan = new Scanner(System.in);
int userNum;
String neg;

public void getUserNum()

[code]...

View Replies View Related

User Input Student Information - Print Out Name With Grade In Descending Order

Nov 23, 2014

I had to make a program that allowed the user to enter the number of students and the students names and grades and then print out the name with the grade in descending order. right now I only have it where it prints the names out in descending order. how do I get it the print out with the grade?

Here is my code

import java.util.*; 
public class Grades {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of students: ");
int numofstudents = input.nextInt();

[Code] .....

View Replies View Related

Input 10 Integer Numbers Into Array And Determine Maximum Value Entered

Apr 22, 2015

a. Write a Java program to input 10 integer numbers into an array named fmax and determine the maximum value entered. Your program should contain only one loop, and the maximum should be determined as array element values are being input. (Hint: Set the maximum equal to the first array element, which should be input before the loop used to input the remaining array values.)

b. Repeat 1a, keeping track of both the maximum element in the array and the index number for the maximum. After displaying the numbers, display these two messages:

The maximum value is: _________
This is element number __________ in the list of numbers

Have your program display the correct values in place of the underlines in the messages.

c. Repeat 1b, but have your program locate the minimum value of the data entered.

I did parts a and b but for part see i just want to know if i did it correctly or not

import java.util.Scanner;
public class MinimumValueArray {
public static void main(String[] args) {
//Variable Declaration
Scanner keyboard = new Scanner(System.in);
int size = 10;

[Code] ,.....

When I run it i get this The minimum value is 0.0

The element that holds the value is 0 right away. is this right for the minimum or am i supposed to enter values and it will display the minimum value like in parts a and b wit the maximum? will the minimum just always be 0 or ?

View Replies View Related

Program That Use Array To Store 10 Numbers

Oct 16, 2014

i'm trying to write a program that uses an array to store 10 numbers. The numbers should be randomly generated ( Math.random() ), and they should be between 1 and 100 ( 1 and 100 inclusive ). The program should produce an output like the one below:

Element 1 = 23 ( Odd )
Element 2 = 15 ( Odd )
Element 3 = 32 ( Even )
Element 4 - 10 ( Even )
Element 5 - 99 ( Odd )
Element 6 - 1 ( Odd )

[Code]...

I have written code for this but its only showing me 0's after first number can you check whats wrong with my code. my code is.

class even/odd{
public static void main(String[]args){
int y=0;
int z=0;
int[] array= new int[11];
for(int x=1; x <array.length ; x++){
array[x]= (int) (Math.random()* 100);
 
[Code]...

View Replies View Related

Store Numbers In Array Then Sort

Feb 19, 2014

Code below. I am not sure if my logic is correct. I want to prompt a user to enter registration numbers from 100 to 1000, store the numbers in an array then sort them.

import java.util.Scanner;
class regnumber
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("registration number ", 100,1000);

[Code] ....

View Replies View Related

Check If Letter Entered By User Matches The One In Array

Jun 10, 2014

/**
* Auto Generated Java Class.
*/
import java.util.*;
public class Hangman {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
int guess;
boolean revealed[] = {false, false, false, false, false};
String word [] = {"c", "a", "n", "a", "d", "a"};

[Code] ....

I am not sure how to make the program check if the letter entered by the user matches the one in the array. also i am not sure how to make the program run again with a new word.

View Replies View Related

Read Characters From Txt File / Store Them Into 2D Array And Print Information

Oct 10, 2014

The point of this program is to read characters from a txt file and store them into a 2D array. After this has been accomplished, the information is to be printed in the same manner it is read from in the txt file.

Here is the code I have so far:

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Main
{
public static void main(String[] args) throws FileNotFoundException

[Code] ....

And this is the error I am receiving when trying to accomplish the goal of the project:

Exception in thread "main" java.lang.NumberFormatException: For input string: "############"
at java.lang.NumberFormatException.forInputString(Unk nown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at Maze.<init>(Maze.java:15)
at Main.main(Main.java:20)

What's going on here and how I can correct this?? The information I am trying to store in a 2D array and then print is this:

############
#.#........#
#.#.######.#
#.#....#...#
#.###.*#.#.#
#...####.#.#
#.#.#..#.#.#
#.#.#.##.#.#
#o#......#.#

View Replies View Related

Take Replacement String Entered By User And Print Out New String

May 22, 2014

I'm having trouble with the last few lines of the code. It's supposed to take a replacement string entered by the user and print out the new string. For some reason it's now allowing me to enter a replacement string

import java.util.Scanner;
public class Project02 {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a long string: ");
String lString = keyboard.nextLine();

[Code] ....

Output:

Enter a long string: the quick brown fox jumped over the lazy dog
Enter a substring: jumped
Length of your string: 44
Length of your substring: 6
Starting position of your substring in string: 20
String before your substring: the quick brown fox
String after your substring: over the lazy dog
Enter a position between 0 and 43: 18
The character at position 18 is x

Enter a replacement string: Your new string is: the quick brown fox over the lazy dog <------ isn't taking user input

View Replies View Related

Java Reverse Order Using Pointers?

Oct 9, 2014

This is what I have to do:Write a program that takes a string of someone's name and prints it out last name first. Your program must use pointers, not array subscripts. You may use the available string manipulation functions if you find an opportunity.

Example:

"George Washington"
"Washington, George"

I am not sure how to reverse the name, I have been looking in my textbook and online and cannot figure it out. This is what I have put together so far, it does not run. At the end it says unnecessary return value.

import java.util.*;
import java.util.Scanner;
public class Test {
public static void main ( String [] args ) {
Scanner sc = new Scanner(System.in); 
System.out.print("Enter name: ");
String name = sc.nextLine(); 
String lastname = "";
String firstname = "";
for(int i = 0; i < name.length(); i++) {
if(name.charAt(i) == ' ')

View Replies View Related

How To Reverse Order Of Words In A Sentence

Nov 29, 2012

I want to write an application that inputs a sentence, tokenizes the words with method split and reverse the words (not the letters)...I am stuck at the last part: how to reverse them...should I use the method reverse(); ?

Here is my code..

import java.util.Scanner;
import java.util.StringTokenizer;
public class ReversedWords {
//execute application
public static void main( String [] args) {
//get sentence

[code]....

View Replies View Related

How To Print All Numbers Of Array In Java

Jan 1, 2015

This is my code

package com.arraydemo;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
public class ArrayStructures {
public long[] theArray;
public int arraySize;
public ArrayStructures(int size)

[code]....

and i am getting this output

----------
! 1712 !2156|
----------
! 1713 !4583|
----------
! 1714 !3981|
----------

[HENRY: 6000+ LINES DELETED -- Isn't it a bit ridiculous hard to read when you flood a post with thousands of output lines?]

----------
! 4998 !3094|
----------
! 4999 !836|
----------
12:10:56

I am expecting Number to be print from Index ) but they are not printing ,why?

If I use arraysize like 2000 I am getting all number starting from 0 to 1999 .why?

View Replies View Related

Reverse Double Linked List In Java - Descending Order

Sep 12, 2014

I have the following double linked list and I'm supposed to order it descending (reverse) using the printInReverse() method; since the list orders itself ascending when the numbers are added, how could I order it descending in this method? Here's the code without implementing descending/reversing methods:

package test;
import java.util.Scanner;
public class MyList {
private Scanner userInput;
private Integer selectedOption;
private MyListElement firstElement = null;
private boolean exitRequested = false;

[Code] ....

I tried to declare a previousElement variable but I didn't figure out how I'd do that.

View Replies View Related

Display Contents Of File In Reverse Order - Output To Console

Jun 24, 2014

Create a class that allows the user to select a file and output the contents of the file to the console. Recommend using a text file to display, java files are text files. You may want to put this code in a method to allow you to complete the remainder of this assignment without overwriting your code.

- You should ask the user to enter the full path to your file to make certain you are processing the correct file.

- Modify your code/add a method to display the contents of the file in reverse order. You do not need to reverse the characters on each line but simply output the lines of the file in reverse order.

Hint: read the content of the file into an ArrayList and then traverse the ArrayList.

this is what i go so far.

package classActivity;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Select
{
public static String enterFilePath()

[Code] ....

View Replies View Related







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