473,388 Members | 1,257 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Java beginner problem: arrays and ints

how do i write a java program tht will store seven integer values in an array of type integer......please helppppp... this is what i got but not sure about it...thnkss...and it has to include reverse order.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class SevenIntegers
{
public static void main(String args[])
{
reader = new BufferedReader(new InputStreamReader(System.in));

int numbers[] = new int[7];

System.out.println("Please enter some integers:");
{
for (int i = 0; i < numbers.length; i++)
{
System.out.print(i + 1 + ": ");
numbers[i] = readNumber();
}
}


System.out.println("IOException! Quitting: " + e.getMessage());
return;

System.out.println("You entered: ");
for (int i = 0; i < numbers.length; i++)
{
System.out.println(numbers[i]);
}

System.out.println("Backwards, that's: ");
for (int i = numbers.length - 1; i >= 0; i--)
{
System.out.println(numbers[i]);
}

int largestIndex = 0;
for (int i = 1; i < numbers.length; i++)
{
if (numbers[i] > numbers[largestIndex])
largestIndex = i;
}

System.out.println("The biggest number was " + numbers[largestIndex] + " at index: " + largestIndex);

int smallestIndex = 0;
for (int i = 1; i < numbers.length; i++)
{
if (numbers[i] < numbers[smallestIndex])
smallestIndex = i;
}

System.out.println("The smallest number was " + numbers[smallestIndex] + " at index: " + smallestIndex);
}

int number = Integer.parseInt(textEntered);
{
System.out.println("What was that?");

f(i=a.length-1;1>=0;i--);
System.out.print();
}
}
Dec 3 '07 #1
3 1604
JosAH
11,448 Expert 8TB
I changed your topic title to something sensible. A bit of advice: don't try to complete
several different programs simultaneously; try one after the other. As it is now all
yout attempts are a mess.

kind regards,

Jos
Dec 3 '07 #2
samido
52
how do i write a java program tht will store seven integer values in an array of type integer......please helppppp... this is what i got but not sure about it...thnkss...and it has to include reverse order.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class SevenIntegers
{
public static void main(String args[])
{
reader = new BufferedReader(new InputStreamReader(System.in));

int numbers[] = new int[7];

System.out.println("Please enter some integers:");
{
for (int i = 0; i < numbers.length; i++)
{
System.out.print(i + 1 + ": ");
numbers[i] = readNumber();
}
}


System.out.println("IOException! Quitting: " + e.getMessage());
return;

System.out.println("You entered: ");
for (int i = 0; i < numbers.length; i++)
{
System.out.println(numbers[i]);
}

System.out.println("Backwards, that's: ");
for (int i = numbers.length - 1; i >= 0; i--)
{
System.out.println(numbers[i]);
}

int largestIndex = 0;
for (int i = 1; i < numbers.length; i++)
{
if (numbers[i] > numbers[largestIndex])
largestIndex = i;
}

System.out.println("The biggest number was " + numbers[largestIndex] + " at index: " + largestIndex);

int smallestIndex = 0;
for (int i = 1; i < numbers.length; i++)
{
if (numbers[i] < numbers[smallestIndex])
smallestIndex = i;
}

System.out.println("The smallest number was " + numbers[smallestIndex] + " at index: " + smallestIndex);
}

int number = Integer.parseInt(textEntered);
{
System.out.println("What was that?");

f(i=a.length-1;1>=0;i--);
System.out.print();
}
}
your code is messed dude, just try to rephrase you request and pin poin what help you are looking for, kind regards...
Dec 3 '07 #3
your code is messed dude, just try to rephrase you request and pin poin what help you are looking for, kind regards...

Hi monkey1001 ,

The way you are reading the numbers is wrong. you should create an object to BufferReader and then u have to accept the input values. And remember u r reading input values and the way ur reading the input values is also wrong. and you have'nt declared the variable e anywhere and u r trying to use it. I have made some change to your program and it's working well. please do the changes as i said. and what are the last four lines of ur code mean ?
Dec 3 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: PhilB | last post by:
Hello experts, I am a complete beginner in C++ (although I know C). I am trying to compile the code below, and I get the following error. Can anyone explain to me my mistake? Thanks! PhilB ...
3
by: Bruno van Dooren | last post by:
Hi All, i have some (3) different weird pointer problems that have me stumped. i suspect that the compiler behavior is correct because gcc shows the same results. ...
197
by: Steve Kobes | last post by:
Is this legal? Must it print 4? int a = {{1, 2}, {3, 4}}, *b = a; printf("%d\n", *(b + 3)); --Steve
8
by: masood.iqbal | last post by:
All this time I was under the illusion that I understand the concept of multi-dimensional arrays well ---- however the following code snippet belies my understanding. I had assumed all along...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
458
by: wellstone9912 | last post by:
Java programmers seem to always be whining about how confusing and overly complex C++ appears to them. I would like to introduce an explanation for this. Is it possible that Java programmers...
26
by: Christoph Zwerschke | last post by:
You will often hear that for reasons of fault minimization, you should use a programming language with strict typing: http://turing.une.edu.au/~comp284/Lectures/Lecture_18/lecture/node1.html I...
8
by: isaac2004 | last post by:
hello, i posted with a topic like this but got no real feedback(prob cuz of lapse in my explanation) so i am trying it again. i am trying to set up a function that brings in a txt file and adds the...
17
by: DiAvOl | last post by:
Hello everyone, merry christmas! I have some questions about the following program: arrtest.c ------------ #include <stdio.h> int main(int agc, char *argv) {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.