hmehta

Greenhorn
+ Follow
since Aug 30, 2000
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by hmehta

No it doesn't produce any exception try it yourse;f I have tried it but it give a result IU cannot explain...
Hey Parag,
Lets put it in more simple way:
public int guessWhat( int arr[] )
{ int x= 0;
for( int i = 0; i < arr.length; i++ )
x = x < arr[i] ? arr[i] : x; // A
return x;
}
Code at A: Lets take a example
Say arr[]={1,2,3,4}
It means array has 4 elements and array length is 4.
Now lets go through for loop
first iteration
for( int i = 0; i < arr.length; i++ )
x = x < arr[i] ? arr[i] : x; // A
return x;
//x=x<arr[0]?arr[0]:x;>
Going from left to right x is assigned to x whihc is equivalent to arr[i] if arr[i] is greater than x and if not then it is equivalent to x itself.
In this case arr[0] is 1 whihc is greater than original value of x which iz zero so x is 1
In second loop x is 1 but the arr[1] is 2 whihc is greater
in third loop x is 2 but arr[2] is 3 whihc is greater
in fourth loop x is 3 but arr[3] is 4 whihc is greater and therfore x becomes 4 whihc is ultimately returned.

I hope this makes it clear.
Hi Archana,
Congrats! Can u send ur notes to hemshef@hotmail.com
23 years ago
Thanks Jaydeep amd Ajith. What would be the advantage of doing this though? I am not very clear.
23 years ago
this program has been taken from the Khalid Mughal book and is onn threads. I am able to comprehend the output of this program.
import java.awt.*;
import java.util.*;
class counter implements Runnable
{
private int currentValue;
private Thread worker;
public counter(String threadName)
{
currentValue=0;
worker=new Thread(this,threadName);
System.out.println(worker);
worker.start();
}
public void run()
{
try
{
while(currentValue<5)
{
System.out.println(worker.getName()+":"+(currentValue++));
Thread.sleep(5);
}
}
catch(InterruptedException e)
{
System.out.println(worker.getName()+"interrupted.");
}
System.out.println("Exit from"+worker.getName()+".");
}
public int getValue()
{
return getValue();
}
}
import java.*;
import java.util.*;
public class client
{
public static void main(String args[])
{
counter counterA=new counter("Counter A");//Creating the thread
try
{
int val;
do
{
val=counterA.getValue();
System.out.println("Main thread:"+val);
Thread.sleep(1000);
}while(val<5);
}
catch(InterruptedException e)
{
System.out.println("Main thread interccepted");
}
System.out.println("Exit from the main thread");
}
}
Is it possible to have two ormore classses in the same file?
23 years ago
I am having trouble comprehending the threads topic completely.
Can anyone recommend a good book for it?
Can anyone explain why reference variables in Java cannot be used as pointers in C++ to manipulate memory.
23 years ago
I have teh following java code, Why doesn't java allow any printing after decalring the variables.. See following..
import java.*;
public class bath
{
//initialization at the point of definition
private String s1=new String("Happy"),
s2="happy",s3,s4;
soap ivory;
int i;
float toy;
//Doesn't allow to compile says type expected....
System.out.println("Inside class bath");
//
bath()
{
System.out.println("Insde Bath()");
s3=new String("joy");
i=47;
toy=3.14f;
ivory=new soap();
}
void print()
{
//Delayed intialization
if(s4==null)
s4="JUY";
System.out.println("The s1 value is"+s1);
System.out.println("The s2 value is"+s2);
System.out.println("The s3 value is"+s3);
System.out.println("The s4 value is"+s4);
System.out.println("The ivalues is"+i);
System.out.println("the toy value is"+toy);
System.out.println("the soap value is"+ivory);
}
public static void main(String args[])
{
bath b=new bath();
b.print();
}

}
23 years ago
This seems very contradictory to what I have read and heard. Everythingin Java is passed by value whether its is object or primitives. I checked many book but all of them say this..
23 years ago
Since there are no pointers in Java unlike C/C++,
is everything done by reference. Can anyone explain giving examples or suggest a book which give good explanation?
Is it as simple as the * being removed in java
for example Char * c in C++ means c ontains an address whihc ontaines acharacter variable. So in java what would String c mean the same thing that c contain an adress whihc ontains a string variable? Could anyone elaborate?
23 years ago
You are right!! I tried it on Sun JDK 1.2 and it didn't work.
Can anybody recommen good date utlities in java as aI find using the gregarian calendar class pretty painfule. For example I want o subtract two dates in different formats etc etc. Is ther anything alreday written out there whihc one can use??
23 years ago
Cool got it!!!
Thanks Stephanie for your time and effort!!!
23 years ago
I van undertsnd that Swap(Object a, Object b)
will not work as they are object s but
Swap(int x, int y) Why will this not work???
23 years ago