473,762 Members | 7,418 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I'm new to Java, need help with Arrays

5 New Member
I need to now how to compare the elements of two arrays. Here is my program. Now I need to compare each element. So I can print the arrays and the elements that are not the same.


import java.util.*;

public class Grades
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System. in);

System.out.prin tln("How many question are in the quiz?");
int num = keyboard.nextIn t();
keyboard.nextLi ne();

String[] Grades = new String [num];
String[] Student = new String [num];

for (int count = 0; count < Grades.length; count++)
{
System.out.prin tln("Please enter key of the quiz(please upper case) " + count );
Grades[count] = keyboard.nextLi ne();
}

for (int st = 0; st < Student.length; st++)
{
System.out.prin tln("Please enter the student answers " + st );
Student[st] = keyboard.nextLi ne();
}
System.out.prin tln("quiz key\tstudent answer");

for (int a=0; a<Student.lengt h;++a){

System.out.prin tln(" " + Grades [a]+ "\t\t\t" + Student [a]);
}
System.exit(0);


}
}
Mar 26 '07 #1
1 1386
r035198x
13,262 MVP
I need to now how to compare the elements of two arrays. Here is my program. Now I need to compare each element. So I can print the arrays and the elements that are not the same.


import java.util.*;

public class Grades
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System. in);

System.out.prin tln("How many question are in the quiz?");
int num = keyboard.nextIn t();
keyboard.nextLi ne();

String[] Grades = new String [num];
String[] Student = new String [num];

for (int count = 0; count < Grades.length; count++)
{
System.out.prin tln("Please enter key of the quiz(please upper case) " + count );
Grades[count] = keyboard.nextLi ne();
}

for (int st = 0; st < Student.length; st++)
{
System.out.prin tln("Please enter the student answers " + st );
Student[st] = keyboard.nextLi ne();
}
System.out.prin tln("quiz key\tstudent answer");

for (int a=0; a<Student.lengt h;++a){

System.out.prin tln(" " + Grades [a]+ "\t\t\t" + Student [a]);
}
System.exit(0);


}
}
if you have two arrays a and b of reference types and you want to compare the elements at position i of both arrays then you can use

Expand|Select|Wrap|Line Numbers
  1.  if(a[i].equals(b[i]) ) ...
Mar 26 '07 #2

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

Similar topics

7
6686
by: ak | last post by:
am I the only one to say that the java.nio. is bullshit? i have been trying to write some code using it to transfer file over the net. small file it is ok, big file -- problematic. java.lang.OutOfMemoryError at java.nio.Bits.reserveMemory(Unknown Source) at java.nio.DirectByteBuffer.<init>(Unknown Source)
5
8064
by: johnny | last post by:
hello. in C++, you can fake a sub-array by passing something like (array + int). If this was passed to something that takes an array as a parameter, the function will deal with the array using the int as the starting value. for example.... if we have some function with the declaration void someFunctionOnSomeArray(int a)
73
8069
by: RobertMaas | last post by:
After many years of using LISP, I'm taking a class in Java and finding the two roughly comparable in some ways and very different in other ways. Each has a decent size library of useful utilities as a standard portable part of the core language, the LISP package, and the java.lang package, respectively. Both have big integers, although only LISP has rationals as far as I can tell. Because CL supports keyword arguments, it has a wider range...
15
7013
by: Paul Morrison | last post by:
Hi all, I need to come up with some differences between arrays in Java and C, I have searched Google and so far all I have found is the following: Arrays in Java are reference types with automatic allocation of memory. In C, arrays are groups of variables of the same type in adjacent memory. Allocation for dynamic arrays is handled by the programmer. This is an 8 mark question in an old exam paper, so I am assuming there are
10
2357
by: Ole | last post by:
Goodday everybody, i want to create an array that represents data, that has to be transferred to a pdf doc ( iTextSharp ). The problem is, that i seem too loose my faith. Namely, ( i have experiences in c/c++, perl and i thouht in c#, too ), i do not succeed in creating a multidimensional array. I have no experience in creating multidimensional array in c#. The whole process looks so ugly to me,
1
4395
by: BestofAbhi | last post by:
I am consuming Java Web Services in .NET. The Java Web Services have been coded using Apache Axis. The binding style in the WSDL is 'Document' and type is 'Literal'. I have added these Java Web Services both as Web Reference and Reference (ie dll generated using wsdl.exe) in the Project in order to access them. I am able to get the output for web methods that return just a string. However when it comes to complex data like an object /...
458
21393
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 simply aren't smart enough to understand C++? This is not merely a whimsical hypothesis. Given my experience with Java programmers --- the code they write and the conversations they have --- Occam's Razor points to this explanation. For example,...
26
3247
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 just came across a funny example in which the opposite is the case. The following is a binary search algorithm in Java. It searches a value in an ordered array a of ints: public static int binarySearch(int a, int key) {
2
2903
by: rookiejavadude | last post by:
I'm have most of my java script done but can not figure out how to add a few buttons. I need to add a delete and add buttong to my existing java program. Not sure were to add it on how. Can anyone help? my script is below. thank you import java.awt.*; //import all java.awt import java.awt.event.*; //import all java.awt.event import java.util.*; //import all java.util import javax.swing.*; //import all javax.swing class Product...
0
3907
by: r035198x | last post by:
Inheritance We have already covered one important concept of object-oriented programming, namely encapsulation, in the previous article. These articles are not articles on object oriented programming but on Java programming but I will cover all the important aspects of object oriented programming as Java has full support for object-oriented programming even though it is not a fully object-oriented language (in the sense that you can write...
0
9377
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9925
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8814
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6640
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3913
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.