Hey everybody,
I am having lots of trouble storing values in an array and I want to be prompt at the beginning of each value. The values I will enter will be two digit values such as 23, or 42, or 35.
Anyways, i am prompted but there is problem with my loop or (char) print statements but i cant get it to work!!!
This is my code: -
class prompt2 {
-
public static void main(String[] args)
-
throws java.io.IOException {
-
-
int p[] = new int[4];
-
-
for ( int i = 0; i < 4; i++)
-
{
-
System.out.println("Enter the distance from the center to point p" + i + ":\n");
-
p[i] = System.in.read() ;
-
-
System.out.println("The numbers in the array for p are: p0 is: " + p[0] + " p1 is: " + (char) p[1]+ " p2 is: " +
-
(char) p[2]+ " p3 is: " + (char) p[3]);
-
-
Any help is very much appreciated!
Thanks,
Gabe
7 2289
Hey everybody,
I am having lots of trouble storing values in an array and I want to be prompt at the beginning of each value. The values I will enter will be two digit values such as 23, or 42, or 35.
Anyways, i am prompted but there is problem with my loop or (char) print statements but i cant get it to work!!!
This is my code: -
class prompt2 {
-
public static void main(String[] args)
-
throws java.io.IOException {
-
-
int p[] = new int[4];
-
-
for ( int i = 0; i < 4; i++)
-
{
-
System.out.println("Enter the distance from the center to point p" + i + ":\n");
-
p[i] = System.in.read() ;
-
-
System.out.println("The numbers in the array for p are: p0 is: " + p[0] + " p1 is: " + (char) p[1]+ " p2 is: " +
-
(char) p[2]+ " p3 is: " + (char) p[3]);
-
-
Any help is very much appreciated!
Thanks,
Gabe
-
-
-
Use a scanner:
-
import java.util.Scanner;
-
class prompt2 {
-
public static void main(String[] args)
-
throws java.io.IOException {
-
Scanner scan = new Scanner(System.in);
-
int p[] = new int[4];
-
for ( int i = 0; i < 4; i++) {
-
System.out.print("Enter the distance from the center to point p" + i + " :");
-
p[i] = scan.nextInt() ;
-
System.out.println();
-
}
-
System.out.println("The numbers in the array for p are: p0 is: " + p[0] + " p1 is: " + p[1]+ " p2 is: " +
-
p[2]+ " p3 is: " + p[3]);
-
}
-
}
-
-
Why were you typecasting to char?
Wow!!!! I never heard of scanners but it worked!!
Thank you!! TY very much!
Now, are u by chance familiar with the Javelin?
Thanks,
gabe
Wow!!!! I never heard of scanners but it worked!!
Thank you!! TY very much!
Now, are u by chance familiar with the Javelin?
Thanks,
gabe -
-
-
Use a scanner:
-
import java.util.Scanner;
-
class prompt2 {
-
public static void main(String[] args)
-
throws java.io.IOException {
-
Scanner scan = new Scanner(System.in);
-
int p[] = new int[4];
-
for ( int i = 0; i < 4; i++) {
-
System.out.print("Enter the distance from the center to point p" + i + " :");
-
p[i] = scan.nextInt() ;
-
System.out.println();
-
}
-
System.out.println("The numbers in the array for p are: p0 is: " + p[0] + " p1 is: " + p[1]+ " p2 is: " +
-
p[2]+ " p3 is: " + p[3]);
-
}
-
}
-
-
Why were you typecasting to char?
Wow!!!! I never heard of scanners but it worked!!
Thank you!! TY very much!
Now, are u by chance familiar with the Javelin?
Thanks,
gabe
Javelin the sport?
Javelin the sport?
no, sorry.. the java based microcontroller from Parallax.
no, sorry.. the java based microcontroller from Parallax.
What does it do and why did you ask about it?
What does it do and why did you ask about it?
Nah its just the microcontroller i am working with on a project of mine. Its programming language is a subset of Javas
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Paul C-T |
last post by:
Hi,
Am I trying to be too clever here?
I am trying to write a PHP page to enable me to enter values into a form
then write those values to a text file.
I want to use the form & table that...
|
by: Tor Erik Sønvisen |
last post by:
Hi
I need a time and space efficient way of storing up to 6 million bits. Time
efficency is more important then space efficency as I'm going to do searches
through the bit-set.
regards tores
|
by: Brad |
last post by:
I am storing an array which contains about a dozen chracter items to a
Session variable. Later, I need to use this array so I am doing the
following:
Dim eventTypes As String() =...
|
by: guitarromantic |
last post by:
Hey everyone,
I run a site with staff-submitted reviews, and most of them are written
by one author. However, we also do "multiple" reviews. Up until now I
just had a userid for a 'Multiple'...
|
by: Kyle Teague |
last post by:
What would give better performance, serializing a multidimensional array
and storing it in a single entry in a table or storing each element of
the array in a separate table and associating the...
|
by: Martin Jørgensen |
last post by:
Hi,
I'm reading a number of double values from a file. It's a 2D-array:
1 2 3 4 5 6 7
-------------
1 3.2
2 0 2.1
3 9.3
4
|
by: assgar |
last post by:
Hi
Developemnt on win2003 server. Final server will be linux
Apache,Mysql and PHP is being used.
I use 2 scripts(form and process).
The form displays multiple dynamic rows with chechboxs,...
|
by: Jay |
last post by:
I'm trying to store a sequence of operations and values of different types into a single array. It's
a sequence of command word bytes, and a sequence of one or more values (as determined by the...
|
by: pereges |
last post by:
I've to store an array of structures:
typedef struct
{
double origin;
double e_field_at_origin_real, e_field_at_origin_imag;
double direction;
double pathlength;
int depth;
}ray;
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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,...
|
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...
| |