| | |
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 |
-xlint actionlistener android api applet application array automation bi binary blackberry block bluetooth character class client code compile compiler component consumer database desktop developmenthelp eclipse error fractal freeze ftp functiontesting game gameprogramming givemetehcodez graphics gui health html ide idea image int j2me j2seprojects java javac javaee javame javaprojects jetbrains jni jpanel jtable julia learningresources lego linked linux mac main map method mobile myregfun netbeans nonstatic notdisplaying number online printf problem program project qt researchinmotion rotatetext rsa scanner screen server set singleton sms sort spamblocker sql string swing system textfields thread threads time title tree tutorial-sample update variablebinding windows working xor





