Java array
View Answers
March 27, 2009 at 12:02 AM
Hi friend,
Code to solve the problem :
Answer 5 :
public class ArrayExample {
public static void main(String args[])
{
String str[] = "programming java hello".split(" ");
System.out.println(str.length);
String strresult="";
for(int i=str.length-1; i>=0; i--)
{
strresult+=str[i]+" ";
}
System.out.println(strresult);
}
}
March 27, 2009 at 5:39 AM
Answer 2 :
import java.lang.*;
import java.io.*;
public class BinaryToDecimal{
public static void main(String[] args) throws IOException{
BufferedReader bf= new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the Binary value: ");
String str = bf.readLine();
long num = Long.parseLong(str);
long rem;
while(num > 0){
rem = num % 10;
num = num / 10;
if(rem != 0 && rem != 1){
System.out.println("This is not a binary number.");
System.out.println("Please try once again.");
System.exit(0);
}
}
int i= Integer.parseInt(str,2);
System.out.println("Decimal:="+ i);
}
}
March 27, 2009 at 5:40 AM
Hi friend,
Answer 3 :
class TwoDimensionalArray
{
public static void main(String[] args)
{
int TwoDarray[][]=new int[3][3];
for(int i=0; i<3;i++)
{
for(int j=0; j<3;j++)
{
TwoDarray[i][j] = i+j;
}
}
int sum=0;
for(int i=0; i<3;i++)
{
for(int j=0; j<3;j++)
{
if(i!=j)
{
sum+=TwoDarray[i][j];
}
System.out.print(" "+ TwoDarray[i][j]);
}
System.out.println("");
}
System.out.println("Total Sum of Non diagonal elements : "+ sum);
}
}
March 27, 2009 at 6:30 AM
Answer :7
import java.util.*;
public class Strtok {
public static void main(String [] args) {
String Demo = "55|7|40|7|7|9|7|2|95|3|";
StringTokenizer Tok = new StringTokenizer(Demo,"|");
int n=Tok.countTokens();
System.out.println("n : " + n);
int num[] = new int[n];
int count=0;
while (Tok.hasMoreTokens())
{
num[count] = Integer.parseInt(Tok.nextToken().toString());
//System.out.println(num[count]);
count++;
}
int numar[] =new int[num.length];
int numcount=0;
for(int i=0;i<num.length;i++)
{
if(num[i]!=7)
{
numar[numcount]=num[i];
//System.out.println( num[i]);
System.out.println( numar[numcount]);
numcount++;
}
}
for(int i=numcount;i<num.length;i++)
{
numar[i]=0;
}
for(int i=0;i<num.length;i++)
{
System.out.println( numar[i]);
}
}
}
March 27, 2009 at 6:48 AM
Answer : 8
import java.io.*;
import java.util.*;
public class MagicSquareExample {
public static void main(String[] args) throws IOException{
InputStreamReader isr=new InputStreamReader (System.in);
BufferedReader in=new BufferedReader (isr);
int[][]square=getSquare();
print(square);
int c = getConst(square);
}
static int[][] getSquare()throws IOException{
int[][] square1 = {{9,6,3,16}, {4,15,10,5}, {14,1,8,11}, {7,12,13,2}};
int[][] square4 = {{2,13,11,8},{16,3,5,10},{7,12,14,1},{9,6,4,15}};
int[][] square5 = {{3,7,14,16,25},{11,20,23,2,9},{22,4,6,15,18},{10,13,17,24,1},{19,21,5,8,12}};
int[][] square8 = {{1,15,24,8,17},{23,7,16,5,14},{20,4,13,22,6},{12,21,10,19,3},{9,18,2,11,25}};
return square8;
}
static int getConst(int[][]square){
int sum=0;
for(int i=0;i<square.length;i++){
sum+=square[0][i];
}
return sum;
}
static boolean checkLine(int[][] veld) {
boolean returnvalue = true;
for (int rowNumber = 0; rowNumber < veld.length; rowNumber++) {
int som = 0;
for (int colNumber = 0; colNumber < veld.length; colNumber++) {
som += veld[rowNumber][colNumber];
}
//System.out.println("Sum of row " + rowNumber + " is: " + som);
if (som != getConst(veld))
{
System.out.println("Row " + rowNumber + " with values: " + Arrays.toString(veld[rowNumber]) + " adds up to " + som + " instead of " + getConst(veld));
returnvalue = false;
}
}
return returnvalue;
}
static boolean colCheck(int[][]veld){
boolean returnvalue = true;
for(int colNumber=0;colNumber<veld.length;colNumber++){
int som=0;
for(int rowNumber=0;rowNumber<veld.length;rowNumber++){
som+=veld[rowNumber][colNumber];
}
//System.out.println("Sum of column " + colNumber + " is: " + som);
if(som!=getConst(veld))
{
System.out.println("Column " + colNumber + " with values: " + Arrays.toString(veld[colNumber]) + " adds up to " + som + " instead of " + getConst(veld));
returnvalue = false;
}
}
return returnvalue;
}
static int getOrder(int[][] veld)
{
return veld.length;
}
static boolean isAssociative(int[][] veld)
{
int check = checkSum(veld);
System.out.println("Checksum: " + check);
return checkPairs(veld);
}
static int checkSum(int[][] veld)
{
return ((int)Math.pow(getOrder(veld), 2)) + 1;
}
March 27, 2009 at 6:49 AM
static boolean checkPairs(int[][] veld)
{
// use recursion to walk through array
return (checkPairs_helper(0, 0, veld));
}
static boolean checkPairs_helper(int row, int col, int[][]veld)
{
if(row == getOrder(veld) || col == getOrder(veld) )
{
return true;
}else
{
int rowindex = getOrder(veld)-1-row;
int colindex = getOrder(veld)-1-col;
if(veld[row][col] + veld[rowindex][colindex] == checkSum(veld) )
{
if(row + 1 == getOrder(veld) || col + 1 == getOrder(veld))
return true;
else
return checkPairs_helper(row+1, col, veld) && checkPairs_helper(row, col+1, veld);
}else
{
System.out.println("Sum of values: " + veld[row][col] + " + " + veld[rowindex][colindex] + " is not equal to " + checkSum(veld));
return false;
}
}
}
static boolean diagCheck(int[][] veld) {
int sumD_leftToRight = 0;
int sumD_rightToLeft = 0;
for (int rowNumber = 0; rowNumber < veld.length; rowNumber++) {
sumD_leftToRight += veld[rowNumber][rowNumber];
sumD_rightToLeft += veld[rowNumber][veld.length - 1 - rowNumber];
}
if (sumD_leftToRight == getConst(veld) && sumD_rightToLeft == getConst(veld))
return true;
else
return false;
}
static void print(int [][]square){
for(int row=0;row<square.length;row++){
System.out.print("\n\t ");
for(int col=0;col<square.length;col++){
System.out.print(square[row][col]+"\t ");
}
}
}
}
March 28, 2009 at 12:41 AM
Answer 1:
class CharacterFrequency
{
static String s = "hello world";
static char []chars = new char[s.length()];
static char []tmp=new char[s.length()];
public static void main(String args[])
{
s.getChars(0,s.length(),chars,0);
tmp=new char[s.length()];
int ccount=0;
for(int i=0;i<s.length();i++)
{
if(!isVisited(chars[i]))
{
//mcount = matchElement(chars[i],i);
storeVisited(ccount,chars[i]);
ccount+=1;
}
}
for(int i=0;i<ccount;i++)
{
int charcount=0;
for(int j=0;j<s.length();j++)
{
if(tmp[i]==s.charAt(j))
{
// System.out.print(s.charAt(j));
charcount++;
}
}
if(tmp[i]!=' ')
System.out.println(tmp[i] + " : " + charcount);
}
}
public static void storeVisited(int i,char c)
{
tmp[i]=c;
}
public static boolean isVisited(char c)
{
for(int i=0;i<tmp.length;i++)
{
if(c==tmp[i])
{
return true;
}
}
return false;
}
}
March 28, 2009 at 6:46 AM
Answer 9 :
class StringAr
{
public static void main(String[] args)
{
String str="ram";
char[] cArray = str.toCharArray();
char[] ch = new char[cArray.length];
for(int i=0;i<cArray.length;i++)
{
int count=0;
for(int j=i;j<cArray.length;j++)
{
ch[count]=cArray[j];
count++;
}
for(int k=0;k<i;k++)
{
ch[count]=cArray[k];
count++;
}
System.out.println(ch);
}
}
}
Related Tutorials/Questions & Answers:
Java array Java array How can one prove that the
array is not null but empty
Java arrayJava array
Java program to find first two maximum numbers in an
array,using single loop without sorting
array Advertisements
Java ArrayJava Array
a) Write an
array program that perform the following:
i) Declares a String
array initialized with the following strings: ââ?¬Å...?¬Â?.
ii) Write a loop that displays the contents of each element in the
array java arrayjava array q4.array
Write a program that accepts two arrays, an
array of fruit names and an
array of price of
fruits, and a fruit name and returns the price of the fruit. (Assume that a price in the
second
array corresponds
java arrayjava array write a
java method that takes an
array of float values...)){
System.out.println("There are duplicate elements.");
Float
array...++){
array[i]=new Float(arr[i]);
}
Set<Float>
java arrayjava array Two cells is a matrix will be called connected if they are adjacent...], a[3,2], a[3,3] } elements with weight 6
Problem: Implement
Java code which takes 2 dimensional integer
array as input and prints out heaviest island
Array in JavaArray in Java public class tn {
public class State{
String s_name;
int p1;
int p2;
}
public void f(){
State[] s = new State[10];
int [] i = new int[10];
i[0] = 1
Java ArrayIn this section, you will learn about
array in
Java What is Array in Java?What is
Array in
Java? Hi,
What is
Array in
Java?
How to create an
array in
Java and use it?
Thanks
Hi,
Array is very important in
Java as it is used heavily in programming.
Array is
Java is a container object
char array javachar
array java char
array programmes in
java
All capital letters should be replaced with the next letter
sorting array in javasorting
array in java How to sort
array in
Java or JavaScript?
JavaScript Sorting
array tutorial
Java Sort
array of strings...[] args) {
String
array[]=new String[5];
Scanner input = new Scanner
What is array in java with example?What is
array in
java with example? Hi,
I am beginner in
Java and want to learn
Java Array concepts. Which is the best tutorials for learn
Java Array with example codes?
What is
array in
java with example?
Thanks
How to declare array in Java?How to declare
array in
Java? Hi,
How to declare
array in
Java?
Thanks
Hi,
Following is a code of declaration of String
array... more example at
Java Array declaration.
Thanks
java array problemjava array problem suppose i have an
array a[] at a[0] i have value 5,7
the thing is that i want to assign the value of
array a[0]=5,7
to two variable let it be j,k
that is j=5 and k=7
plz help
regards
ArrayArray is it possible to define
array like this..?
int[] intArray = new int[] {4,5,6,7,8}; Explain...?
Yes, you can.
Java Initialize
Array Array in Java_TO_REPLACE_1
Different types of
array used in
Java are One-dimensional, Two... of an
Array
Arrays in
Java for different data types can be declared as follows... in different way, like:
int i[];
Construction of an
array in
Java:ADS_TO_REPLACE_5
array in javascript - Java Beginners://www.roseindia.net/
java/javascript-
array/index.shtml
Hope...
array in javascript how to initialize
array in javascript and can we increase the size of
array later on?
is
Array class in javascript ?
also
array manipulation - Java Beginnersarray manipulation We'll say that a value is "everywhere" in an
array if for every pair of adjacent elements in the
array, at least one of the pair is that value. Return true if the given value is everywhere in the
array Java Array TypesJava Array Types Hi,
Can Some one guide me how many types of
Java Array uses in developing an application. I need the online tutorial to learn syntax or code of the various types of
Java arrays.
Thanks
java program based on arrayjava program based on array write a program to create an
array of 10 integers in main.accept values from the user in that
array .now again ask the use another nomber and pass the
array and the no. entered to function called
arrayarray WAP in
java to store 6 element in
array P and
4 element in
array Q. Produce the third arra
y R containing all element from p &
q arrayarray
array memory allocation is dynamic or static in
java
Java Arrays have dynamic memory allocation
Array in javaArray in
java
In following example we will discuss about
Array in
Java.
Array... in memory at fixed
size. We can use multiple type
array. It can be used in
Java, C..., Boolean, String object. We can store only primitive data in
array. We have
ArrayArray can we create an
array of size 1 lakh in
java programming
array variable in a java programarray variable in a
java program How do i write a program that will prompt the user for a list of 5 prices, that cosist of the sum of all the prices, the average of the prices, and all prices that are higher than the calculated
is _array()is _
array() is_
array() in php
Hi Friend,
This function is of Boolean type.It checks whether a variable is an
array or not.
Here is an example:
<?php
$yes =
array('Hello', 'World');
echo is_
array($yes) ? '
Array is _array()is _
array() is _
array()
Hi Friend,
This function is of Boolean type.It checks whether a variable is an
array or not.
Here is an example:
<?php
$yes =
array('Hello', 'World');
echo is_
array($yes) ? '
Array java program based on arrayjava program based on array Create Student class with attributes... StudentDemo which will have main method. Declare
array of Student object with size 10. Initialize all 10 elements of this
array with new objects. Write logic which
array sort - Java Beginnersarray sort hi all,
can anybody tell me how to sort an
array...
array[], int len){
for (int i = 1; i < len; i++){
int j = i;
int tmp =
array[i];
while ((j > 0) && (
array[j-1] > tmp
ARRAY SIZE. - Java BeginnersARRAY SIZE. Thanks, well that i know that we can use ArrayList... the elements in
array A. Then doubled
array A by multiplying it by 2 and then storing it in
array B. But gives me error.
import java.io.*;
import
Java Array declarationJava Array declaration
In this section you will learn how to declare
array in
java. As we know an
array is collection of single type or similar data type. When an
array is
created its length is determined. An
array can hold fixed
Java Array Declaration
Java Array Declaration
As we declare a variable in
Java, An
Array variable is
declared the same way.
Array variable has a type and a valid
Java identifier
i.e. the
array's array - Java Beginners array:5
what is the length of 2nd
array:4
enter a number for 1st
array: 4
enter a number for 1st
array: 6
enter a number for 1st
array: 2
enter a number for 1st
array: 1
enter a number for 1st
array: 7
How to create and use Array in Java?How to create and use
Array in
Java? Hi,
How to create and use
Array in
Java?
Write program to construct and use the
array.
Thanks
Hi... can read complete example at
Array in
Java.
Thanks
array - Java Beginnersarray Accept a two dimensional
array from the user check if this
array is symetric display a message yes,if it is symetric otherwise display it ,is not symetric
array - Java Beginners*;
and no function,,,
what is the length of 1st
array:5
what is the length of 2nd
array:4
enter a number for 1st
array: 4
enter a number for 1st
array: 6
enter a number for 1st
array: 2
enter a number for 1st
array: 1
enter a number
Java Array - Java BeginnersJava Array Can someone help me to convert this to
java?
I have an
array called Projects{"School", "House", "Bar"}
I want all the possible combinations but only once each pair, for example ["House", "Bar"] is the SAME
Question in Array Implementation (java) ??!Question in
Array Implementation (
java) ??! Good Morning EveryOne
I have
Q in
Java - and if any One have the Answers please tall me ??!!
Question... stores list of â??PhoneEntryâ?? objects. Use an
array of size (MAXSIZE = 1000
Java Array - Java BeginnersJava Array Q4-Write a program to exchange the nondiognal elements of a two dimensional
array A of size NxN without using any other
array ie.
each a[i][j]with a[j][i] where i is not equal j?
Hi Friend,
Please try
Array sorting - Java BeginnersArray sorting Hello All.
I need to sort one
array based on the arrangement of another
array.
I fetch two arrays from somewhere... need to sort the "name"
array alphabetically. I can do that easily using
How to calculate average of array in Java?How to calculate average of
array in
Java? Hi,
I have an integer
array and I want to calculate the average of the values in it.
How to calculate average of
array in
Java?
Thanks
Hi,
You can iterate through
array password - Java Beginnersarray password i had create a GUI of encryption program that used the
array password. my question is can we do the password change program? i mean we change the older password with the new password
Array in Java - Java BeginnersArray in Java Please help me with the following question. Thank you.
Write a program that reads numbers from the keyboard into an
array of type int[]. You may assume that there will be 50 or fewer entries in the
array. Your
Averaging an Array - Java Beginners the average of an
array with the following headers. However, prompt user to enter 10 int and 10 doubles.
a) public static int average(int[]
array)
b) public static double average(double[]
array)
Hi Friend,
Try the following code
ARRAY - Java BeginnersARRAY How To Find Out Unique Elements Of Given
Array...) {
int
array[]={1,2,1,1,3,4,4,3,6,8,0,6,0,3};
int num;
int count;
for(int i = 0... = 0; j < array.length; j++){
if(j >= i){
if(
array[i