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.

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()

hello, me again. thanks for the reply appreciate it.
i am getting thise error and i dont know why.

Scanner input = new Scanner(System.in);

testing.java:4: ';' expected
Scanner input = new Scanner(System.in);
^
1 error

you might wanna past the whole code and numerate each line and mark where you r getting the error

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

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.

okay i changed the + and - of the add and sub value. it works now. but i still cannot get the " less than " to work. thanks in advance.

just noticed my program does not compare to previous numbers inputed but compares it solely to the first num. please help need tips so it will compare to previous number.

to compare the 2nd number with the 3rd number you need to make the variable that equals the 1st number equals to the second number and the variable that equals the 2nd number equal to the new number, that is what i meant by using only 2 variables and then throw the 1st one out in a prin

thanks a lot. i guess i was just not getting the concept of it. appreciated you help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.