|
|
can you please send the java code?
It is for calculating the distance between two position from time information..i need to get the transmission time from one system and reception time of my message in another system..please send the java code for the above..
It is for doing the project called"Discovery and Verification of neighbour position in MANET"..Thank U ..
|
|
|
|
|
I already told you "don't ask for code". This site is not here to do your work for you. If this project is beyond your abilities then you need to talk to your supervisor/manager about it.
|
|
|
|
|
Does anyone know how to find a median of an array? How do we sort it first?
|
|
|
|
|
|
//created by akshgods
import java.util.*;
class median
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int size=5,temp=0,mid=0,pnt1=0,pnt2=0;
System.out.println("Enter the size of array");
size=sc.nextInt();//taking size for array
int a[]=new int[size];
//taking values in array
System.out.println("Enter the values");
for(int i=0;i<size;i++)
{
a[i]=sc.nextInt();
}
//sorting array with bubbule sort in ascending order
for(int i=0;i<size-1;i++)
{
for(int j=0;j<size-i-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
//printing values in ascending order
System.out.println("values in ascending order");
for(int i=0;i<size;i++)
{
System.out.print(" "+a[i]);
}
//finding medean logic
if(size%2==0)
{
pnt1=size/2;
pnt2=pnt1-1;
mid=(a[pnt1]+a[pnt2])/2;
System.out.println("\nmidean is= "+mid);
}
else
{
pnt1=(size+1)/2;
pnt1--;
mid=a[pnt1];
System.out.println("midean is= "+mid);
}
}
}
|
|
|
|
|
|
Why is it giving me a zero.
double percent = 0;
if(condition) {
percent = scrollpane.getHeight() / origIcon.getImage().getHeight(scrollpane);
System.out.print(scrollpane.getHeight() + " / " + origIcon.getImage().getHeight(scrollpane));
System.out.println(" = " + percent);
} else {
}
This returns 309 / 1668 = 0.0 value should be 0.1852..
I know this is basic but I DON'T KNOW. sorry, too tired I guess but I need this to figure out
Thanks
- Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.
- Most of the problem in your life are due to two reasons: you act without thinking, or think without acting.
|
|
|
|
|
Because that's what scrollpane.getHeight() / origIcon.getImage().getHeight(scrollpane) returns, due to integer datatypes.
I don't know Java, but I expect you could do something like:
percent = scrollpane.getHeight();
percent = percent / origIcon.getImage().getHeight(scrollpane);
|
|
|
|
|
well that gives me an idea.. casting should do the trick
Thanks
- Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.
- Most of the problem in your life are due to two reasons: you act without thinking, or think without acting.
|
|
|
|
|
|
thank you very much it works
- Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.
- Most of the problem in your life are due to two reasons: you act without thinking, or think without acting.
|
|
|
|
|
Hello. Can anybody help me create a program that lets user input positive integers and exits if a negative integer is input? the program that outputs max,min, and average of the integers. i have tried to do it since a week and i am stuck in an infinite while loop
|
|
|
|
|
If you show the code* that is failing then people will try to help you.
*Please ensure your code is formatted between <pre lang="java"></pre> tags so it is readable.
|
|
|
|
|
Richard MacCutchan wrote: If you show the code* that is failing He did. In the Quick Answers post that was then closed because it was flagged as a duplicate.
/ravi
|
|
|
|
|
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
System.out.println("Enter a positive integer");
int userinput=in.nextInt();
int maxer=0;
int miner=0;
int sum=0;
int counter=1;
if(maxer<userinput){
maxer=userinput;
counter++;
sum=sum+userinput;
}
if(miner>userinput){
miner=userinput;
counter++;
sum=sum+userinput;
}
int avg= sum/counter;
System.out.println("Your maximum integer is "+maxer);
System.out.println("Your minimum integer is "+miner);
System.out.println("Your average is "+avg);
}
}
This is my code here
|
|
|
|
|
One of the problems with this code is there's no loop present; so the summing and min/max computation (which may not be correct anyway) will only execute once. You may want to use a construct like this:
do {
get user input;
if (input is not negative) {
compute new min/max;
compute sum;
}
while (input is not negative);
display results;
/ravi
|
|
|
|
|
but how do i write input is not negative in code?
i am in new in java so i am still not aware of the syntax.
|
|
|
|
|
|
can u plz tell how many integers do u want to take in program? for max,min and average?
|
|
|
|
|
//programm by askhgods
import java.util.*;
public class array
{
public static void main(String args[])
{
int size=0,sum=0,avg=0,temp=0,f=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter size of array");
size=sc.nextInt(); //size of array to taking integer
int a[]=new int[size];
System.out.println("Enter input numbers in positive integer");
while(f<size)
{
a[f]=sc.nextInt();
if(a[f]<0)
{
break; //break and exit in negative value get inserted
}
f++;
}
if(f==size)
{
for(int i=0;i<size;i++)
{
sum=sum+a[i];
}
avg=sum/size; //avarage of integers value
//max and min with bubble sort techniche
for(int i=0;i<size-1;i++)
{
for(int j=0;j<size-i-1;j++)
{
if(a[j]<a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
f=0;
int max=a[f];
int min=a[size-1];
//printing values thats u want
System.out.println("\nAvarage of integers= "+avg+"\nMax integer value= "+max+"\nMin integer value= "+min);
//printing sorted list array to understand u easily
System.out.println("\nSorted list array ");
for(int i=0;i<size;i++)
{
System.out.println(a[i]);
}
}
}
}
|
|
|
|
|
i wanna make a class in JComponent library in the following way :
class HelloComponent extends JComponent {
but the "JComponent cannot be resolved to a type" message would show up . any idea ?
|
|
|
|
|
You need to show a bit more of your code and the actual line that the message occurs on. Did you import the JComponent definition?
|
|
|
|
|
Eclipse can't find the type JComponent
What kind of JComponent is it? What kind of GUI are you creating?
That name is used way to.
regards Torsten
I never finish anyth...
|
|
|
|
|
I have a task at hand for designing persistence layer for an application that should be generic. It is kind of application that will provide infrastructure for doing activities.I need help regarding how should my approach be towards it . Persistence can be through either XML or through database or through configuration files. Please provide me points to keep in mind as well as any special design considerations I should be aware of.
|
|
|
|