| | |
simple question about my code
Thread Solved |
•
•
Join Date: Sep 2009
Posts: 30
Reputation:
Solved Threads: 0
Hello everyone. I am required to write a simple code that reads 10 numbers and displays the largest and last number entered. I thought i would be able to do this easily but for some reason the numbers wont get assigned to the variables like i thought.
thats what i made, which i thought would work fine...but then the output says the largest and number variables are equal to 0. I set them to 0 at the top, but how come they arnt assigned the new numbers when the while loop executes?
Java Syntax (Toggle Plain Text)
import java.util.Scanner; public class LargestNumber { public static void main(String[] args) { int largest=0; int number=0; int counter=1; Scanner input=new Scanner (System.in); System.out.println("Please enter a number: "); number=input.nextInt(); number=largest; counter++; while (counter <= 10){ System.out.println("Enter another number: "); number=input.nextInt(); if (number>largest) number=largest; counter++; } System.out.println("Last number entered was: "+ number+"."); System.out.println("The largest number entered was: "+ largest+"."); } }
thats what i made, which i thought would work fine...but then the output says the largest and number variables are equal to 0. I set them to 0 at the top, but how come they arnt assigned the new numbers when the while loop executes?
![]() |
Similar Threads
- simple question about VB code used is SQL Reporting services (VB.NET)
- simple question (Python)
- help! simple question (Python)
- simple question (C++)
- This has to be a simple question to answer. (Visual Basic 4 / 5 / 6)
- can some one make me a simple perl code (Perl)
- Simple Counter Code (ASP)
Other Threads in the Java Forum
- Previous Thread: Drwaing Circles?
- Next Thread: catch without try
| Thread Tools | Search this Thread |
account android api applet application array arrays automation awt bidirectional binary birt bluetooth busy_handler(null) chat class classes client code columns component database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer homework html ide image inetaddress inheritance integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jlabel jme jni jpanel jtextfield julia linux list loop map method methods midlethttpconnection mobile mobiledevelopmentcreatejar monitoring myaggfun netbeans newbie nullpointerexception open-source plazmic print problem program programming project property recursion ria scanner search server set smart sms smsspam sort sourcelabs splash sql sqlite static string subclass support swing testautomation threads tree webservices windows






