| | |
need help with java program.
Thread Solved |
•
•
Join Date: Nov 2007
Posts: 6
Reputation:
Solved Threads: 0
hi i have this assingment due very soon and i am totally stumped. I have to use java and im not good with it at all , ive' been searching everywhere and i can't find anything that would help me. Hopefully you guys can help me , thanks in advance.
i am suppose to do this.
Write a program that does the following.
Ask the user how much data they have
For every number entered print the number and whether it was larger or smaller, and by how much, than the previous number.
Compare the first number to 0.
for example, (comparing to first number (0) 10, 10 greater // 20, 10 greater // 50, 30 greater.
this is what i have so far :
{public static void main(String[] args)
{int num1=0,nnum,subvalue,addvalue,sum,counter;
Scanner input = new Scanner(System.in);
System.out.print("how much data do you have? ");
counter=input.nextInt();
counterkb=counter+kb.nextInt();
num1=input.nextInt();
System.out.print("enter a number");
nnum=input.nextInt();
subvalue=num1-nnum;
addvalue=num1+nnum;
for (num1=1;counter<=counter+kb;nnum=num1+1)
{sum=num1+nnum;}
System.out.println("The sum is" +sum);
if(num1>nnum);
{System.out.print(num1 +" is greater than nnum by "+subvalue);
{
if(num1<nnum);
{ System.out.print(nnum +" is less than num1 by "+addvalue);
}
}
}
}
}
i think the program should be really simple. we did not learn any strings or arrays, really basic java. im not sure how i am suppose to output weather the number was greater/less than how many. and i am not sure how i am suppose to set the counter and loop// + what loop i should use. any help would be greatly appreciated. thanks in advance again.
i am suppose to do this.
Write a program that does the following.
Ask the user how much data they have
For every number entered print the number and whether it was larger or smaller, and by how much, than the previous number.
Compare the first number to 0.
for example, (comparing to first number (0) 10, 10 greater // 20, 10 greater // 50, 30 greater.
this is what i have so far :
{public static void main(String[] args)
{int num1=0,nnum,subvalue,addvalue,sum,counter;
Scanner input = new Scanner(System.in);
System.out.print("how much data do you have? ");
counter=input.nextInt();
counterkb=counter+kb.nextInt();
num1=input.nextInt();
System.out.print("enter a number");
nnum=input.nextInt();
subvalue=num1-nnum;
addvalue=num1+nnum;
for (num1=1;counter<=counter+kb;nnum=num1+1)
{sum=num1+nnum;}
System.out.println("The sum is" +sum);
if(num1>nnum);
{System.out.print(num1 +" is greater than nnum by "+subvalue);
{
if(num1<nnum);
{ System.out.print(nnum +" is less than num1 by "+addvalue);
}
}
}
}
}
i think the program should be really simple. we did not learn any strings or arrays, really basic java. im not sure how i am suppose to output weather the number was greater/less than how many. and i am not sure how i am suppose to set the counter and loop// + what loop i should use. any help would be greatly appreciated. thanks in advance again.
•
•
Join Date: Oct 2007
Posts: 17
Reputation:
Solved Threads: 2
make sure u are using the scanner class right, remember it reads until the first space is u do scanner.next() and if you do scanner.nextInt() will scan the next set of number until it gets to a space, my advise is to make it simple to work create as many variables as data is gonna be entered now if you havent gone over arrays yet try reading 2 data entries the first time and then do what ever you need to do with them and then throw one away and get the next data on the string using scanner.nextInt()
•
•
Join Date: Oct 2007
Posts: 17
Reputation:
Solved Threads: 2
int num1=0,nnum,subvalue,addvalue,sum,counter;
i forgot on that line i think if you declare a variable you have to put a ';' after and if you dont declar it then you can do ','
int num = 0'
int nnum, subvalue, addvalue, sum, counter;
now i m not sure if that will help because i try to avoid doing it like that because it easier for me to look for errors
i forgot on that line i think if you declare a variable you have to put a ';' after and if you dont declar it then you can do ','
int num = 0'
int nnum, subvalue, addvalue, sum, counter;
now i m not sure if that will help because i try to avoid doing it like that because it easier for me to look for errors
Last edited by uonsin; Nov 21st, 2007 at 12:41 am.
•
•
Join Date: Nov 2007
Posts: 6
Reputation:
Solved Threads: 0
okay this is what i have so far...
the program runs but : it does not do what i want it to do . lol
{int oldNumber=0,newNumber,subvalue,addvalue;
Scanner input = new Scanner(System.in);
System.out.print("The first number is " +oldNumber);
do {
System.out.print("Enter a new number: ");
newNumber=input.nextInt();
subvalue=oldNumber-newNumber;
addvalue=newNumber+oldNumber;
if (newNumber > oldNumber)
{ System.out.print("greater by "+subvalue);
} else if (newNumber < oldNumber)
{ System.out.print("less by "+addvalue);
} else
{ System.out.print("don't know yet");
}
} while (oldNumber>=0);
===============================================
RESULTS:
The first number is 0Enter a new number: 2
greater by -2Enter a new number: 5
greater by -5Enter a new number: 2
greater by -2Enter a new number: 1
greater by -1Enter a new number: 2
greater by -2Enter a new number:
===============================================
that is what i am getting. a minus sign in front of the number which i do not want. AND the "less than" and "greater than" does not work. And it wont tell me how much larger or smaller the new value was. ( named the variables "addedvalue" "subvalue" )
pls help.
the program runs but : it does not do what i want it to do . lol
{int oldNumber=0,newNumber,subvalue,addvalue;
Scanner input = new Scanner(System.in);
System.out.print("The first number is " +oldNumber);
do {
System.out.print("Enter a new number: ");
newNumber=input.nextInt();
subvalue=oldNumber-newNumber;
addvalue=newNumber+oldNumber;
if (newNumber > oldNumber)
{ System.out.print("greater by "+subvalue);
} else if (newNumber < oldNumber)
{ System.out.print("less by "+addvalue);
} else
{ System.out.print("don't know yet");
}
} while (oldNumber>=0);
===============================================
RESULTS:
The first number is 0Enter a new number: 2
greater by -2Enter a new number: 5
greater by -5Enter a new number: 2
greater by -2Enter a new number: 1
greater by -1Enter a new number: 2
greater by -2Enter a new number:
===============================================
that is what i am getting. a minus sign in front of the number which i do not want. AND the "less than" and "greater than" does not work. And it wont tell me how much larger or smaller the new value was. ( named the variables "addedvalue" "subvalue" )
pls help.
![]() |
Similar Threads
- put the Dos 's command into java program? (Java)
- Running java command thru java program (Java)
- Help with Java program writing (Java)
- Java program sample for getting Systeminfo (Java)
- JAVA program help (Student/Grades) (Java)
- Help with a java program home work assignment (Java)
Other Threads in the Java Forum
- Previous Thread: how to download a file without opening file download dialog box
- Next Thread: integer comparison
| Thread Tools | Search this Thread |
2dgraphics 3d @param affinetransform android api apple applet application arc arguments array arrays automation banking binary binarytree bluetooth chatprogramusingobjects class client code color compare component count database derby design detection eclipse eclipsedevelopment encryption error fractal game givemetehcodez graphics gridlayout gui guitesting helpwithhomework html ide if_statement image integer interface j2me java java.xls javadesktopapplications javaprojects jni jpanel julia keytool keyword linux list macintosh map method methods mobile netbeans object os pong problem producer program programming project projectideas property read recursion reference replaysolutions rim scanner server set size sms sort sql stop string swing terminal threads transforms tree ui unicode validation web windows





