473,383 Members | 1,861 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,383 software developers and data experts.

I'm new to Java, need help with Arrays

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.println("How many question are in the quiz?");
int num = keyboard.nextInt();
keyboard.nextLine();

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

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

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

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

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


}
}
Mar 26 '07 #1
1 1366
r035198x
13,262 8TB
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.println("How many question are in the quiz?");
int num = keyboard.nextInt();
keyboard.nextLine();

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

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

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

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

System.out.println(" " + 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
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. ...
5
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...
73
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...
15
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...
10
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...
1
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...
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...
2
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...
0
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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...
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:
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 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.