468,253 Members | 1,314 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,253 developers. It's quick & easy.

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 1282
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

Post your reply

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

Similar topics

15 posts views Thread by PhilB | last post: by
3 posts views Thread by Bruno van Dooren | last post: by
197 posts views Thread by Steve Kobes | last post: by
458 posts views Thread by wellstone9912 | last post: by
26 posts views Thread by Christoph Zwerschke | last post: by
8 posts views Thread by isaac2004 | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.