I am a complete newbie at Java, and I've been assigned a project which needs to take a user's input as a char array, and return the length of the array, return the values in the array, copy the array to a new object (without using clone(); ), concatenate the array, and find whether an array is a subString of the original.
I'm using blueJ, and the first problem I'm having is that I can't figure out the input format, ie when I create a new object, it asks for int length and char value, but if i put 'a','b','c' for char value, it has error, same with 'a'+'b'+'c' and any other thing I can think of. 'a' on its own works. At one point I did get to put in more than 1 char, but it returned a bunch of symbols.
Any one familiar with BlueJ? Thanks
14 2270
Are you able to write the program without using blueJ? Do you know about System.In?
Read about the java.util.Scanner class.
Any one familiar with BlueJ?
By the way, BlueJ is just an IDE, not Java. If it will work in Java (from command line), it should work in any IDE, no matter if it's BlueJ, Eclipse, Netbeans or anything else. And if it works in an IDE, it should also work without.
As r0 said, check the Scanner class. It allows to do many very neat things with various types of input.
Greetings,
Nepomuk
Thanks for your feedback, but the tutors have specified we're not allowed to use any extra classes or any shortcuts etc. I have solved this problem now anyway, thanks.
Thanks for your feedback, but the tutors have specified we're not allowed to use any extra classes or any shortcuts etc. I have solved this problem now anyway, thanks.
You are not allowed to use the Scanner class?
You are not allowed to use the Scanner class?
I see that type of questions a lot nowadays; a template of such a question could be:
"how to solve <T> without using <all the neat stuff that solves T easily>".
I am not going to answer them anymore; they're no fun; just homework.
kind regards,
Jos
I see that type of questions a lot nowadays; a template of such a question could be:
"how to solve <T> without using <all the neat stuff that solves T easily>".
I am not going to answer them anymore; they're no fun; just homework.
kind regards,
Jos
Those type of questions belong in a games forum IMO. I really don't see how such questions teach people proper programming.
Those type of questions belong in a games forum IMO. I really don't see how such questions teach people proper programming.
Well, in some cases it can actually be useful. I for example have to write my current project so that it will work with JRE1.4.x - there are still people around, who use it, although it's near it's end of life circle. And as the Scanner class wasn't introduced until Java 1.5, I have to solve any such problems without Scanners. Luckily it's mainly "nextLine()" or "hasNext()" I'd be using and those can be done with a BufferedReader. Still, annoying. I like Scanners.
The other point of such homework is of course, that it's easier for the teacher to see, if the students understood what he taught them. A lot of teachers love saving themselves from checking stuff they didn't teach in class.
Greetings,
Nepomuk
Well, in some cases it can actually be useful. I for example have to write my current project so that it will work with JRE1.4.x - there are still people around, who use it, although it's near it's end of life circle. And as the Scanner class wasn't introduced until Java 1.5, I have to solve any such problems without Scanners. Luckily it's mainly "nextLine()" or "hasNext()" I'd be using and those can be done with a BufferedReader. Still, annoying. I like Scanners.
The other point of such homework is of course, that it's easier for the teacher to see, if the students understood what he taught them. A lot of teachers love saving themselves from checking stuff they didn't teach in class.
Greetings,
Nepomuk
I wasn't talking particularly about the Scanner class there.
IMO a good Java assignment involves a scenario where the student is asked to design and implement some classes and interfaces to model/solve the scenario in an extensible way.
I wasn't talking particularly about the Scanner class there.
IMO a good Java assignment involves a scenario where the student is asked to design and implement some classes and interfaces to model/solve the scenario in an extensible way.
I'm sure a lot of teachers would think that's far to much work for them. ^^
In this specific case of course, the teacher could ask the students to write a sort of specialised (and reusable) Scanner class... But well, I'm no teacher, so I'll just keep on answering questions here.
Greetings,
Nepomuk
But well, I'm no teacher, so I'll just keep on answering questions here.
I'm not; they say that there are no stupid questions; I beg to differ here; I personally
find the level of questions being asked here abominable; and the level lowers
every day. One way or another this forum attracts the lazy bums just because
we patiently keep on answering those stupid homework questions.
kind regards,
Jos
I'm not; they say that there are no stupid questions; I beg to differ here; I personally
find the level of questions being asked here abominable; and the level lowers
every day. One way or another this forum attracts the lazy bums just because
we patiently keep on answering those stupid homework questions.
kind regards,
Jos
Oh, there are stupid questions (although there are more stupid answers around, I guess) - but actually, we didn't do much in this case, did we? We said "use a Scanner or write your own class" and now it works. Sure, they should search and think for themselves. They just need someone to tell them so. Bit ironic, isn't it?
Greetings,
Nepomuk
Guys, before you bag me too much, as it turns out, the program worked all along, the only thing I didn't know was the input format, ie when the program pops up asking for input, i didn't know to put in
And if you wanna complain about stupid questions, blame crappy tutors for not teaching what we actually need first.
Guys, [...] as it turns out, the program worked all along, the only thing I didn't know was the input format,...
Well, I'm glad it works now. :-)
And if you wanna complain about stupid questions, blame crappy tutors for not teaching what we actually need first.
Actually, we were complaining about the tutors and the tasks they give their students all along. Sorry if it seemed to be about you.
Greetings,
Nepomuk
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ying Yang |
last post by:
Hi,
whats the difference between:
char* a = new char;
char* b = new char;
char c ;
|
by: Tim Johansson |
last post by:
I'm new to C++, and tried to start making a script that will shuffle an
array. Can someone please tell me what's wrong?
#include <iostream.h>
#include <string.h>
int main () {...
|
by: buda |
last post by:
Hi,
given the following code,
....
int main( void ) {
char *a = { "abc", "def", "ghijkl", "o", "prs" }; // for example
....
}
|
by: Merrill & Michele |
last post by:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
char *p;
p=malloc(4);
strcpy(p, "tja");
printf("%s\n", p);
free(p);
return 0;
|
by: jab3 |
last post by:
(again :))
Hello everyone.
I'll ask this even at risk of being accused of not researching adequately.
My question (before longer reasoning) is: How does declaring (or defining,
whatever) a...
|
by: GRoll35 |
last post by:
I get 4 of those errors. in the same spot. I'll show my parent class,
child class, and my driver.
All that is suppose to happen is the user enters data and it uses
parent/child class to display...
|
by: rob.kirkpatrick |
last post by:
Hello
I need to populate an array of char arrays at run-time. A very
simplifed version of the code is below.
char ** list should contain cnt char arrays. The values of char ** list
are set by...
|
by: sarathy |
last post by:
Hi,
I need clarification regarding signed characters in the C
language.
In C, char is 1 byte. So
1. Unsigned char
- ASCII CHARACTER SET
- EXTENDED CHARACTER SET
|
by: Michael B Allen |
last post by:
Hello,
Early on I decided that all text (what most people call "strings" )
in my code would be unsigned char *. The reasoning is that the elements
of these arrays are decidedly not signed. In...
|
by: Dennis Jones |
last post by:
Hi all,
1) Let's say you have two char 's of the same size. How would you write a
no-fail swap method for them? For example:
class Test
{
char s;
void swap( Test &rhs )
{
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |