What's wrong with my code/ :-/
I keep trying to program a code to count the 6 digits of a si-digit number but I keep getting a (cannot find symbol) error. Can someone point out were I am going wrong?
Code:
import java.util.Scanner;
public class Integer
{
public static void main(String[]args)
{
int Number;
Scanner console = new Scanner (System.in);
System.out.print("Enter six-figure digit: ");
Number = Integer.parseInt(console.nextLine());
int Result;
Result = (Number /100000);
Result = Result + ((Number % 100000) / 10000);
Result = Result + ((Number / 1000));
Result = Result + ((Number % 1000) / 100);
Result = Result + (Number / 10);
Result = Result + ((Number % 10) / 1);
System.out.print("The sum of the six-figure digit is: " + Result);
}
}
Re: What's wrong with my code/ :-/
You have named your scanner "console", but you do not use it anywhere.
http://docs.oracle.com/javase/1.5.0/...l/Scanner.html
Re: What's wrong with my code/ :-/
Please give us the full error and where it occurs.
(I've corrected your close code tag typo)
Note that console is used in this line:
Code:
Number = Integer.parseInt(console.nextLine());
and even if it wasn't that would not generate a "cannot find symbol" compiler error.
Re: What's wrong with my code/ :-/
Quote:
Originally Posted by
Tolls
Please give us the full error and where it occurs.
(I've corrected your close code tag typo)
Note that console is used in this line:
Code:
Number = Integer.parseInt(console.nextLine());
and even if it wasn't that would not generate a "cannot find symbol" compiler error.
What is there now is different to what was originally posted, where in.nextLine() was used.
Re: What's wrong with my code/ :-/
Oh right, but not using a variable will not give a "cannot find symbol" compiler error, so unless something else has been edited then that won't be the problem.
Re: What's wrong with my code/ :-/
Hello there I am new to Java and have been getting some help but I cant figure out why I am getting errors please help
import java.util.Scanner;
class VegetablesLab
{
public static void main( String[] args )
{
int apples = 30;
int oranges = 45;
int turnips = 70;
double strawberries = 2.30;
double potatoes = 3.25;
double carrots = 1.25;
String name = "";
String address = "";
String ccnum ="";
String dob = "";
String email = "";
String email2 = "";
String grocery1 = "";
String grocery2 = "";
String grocery3 = "";
String amount1 = "";
String amount2 = "";
String amount3 = "";
Scanner input = new Scanner( System.in );
System.out.println( "Enter your Full Name Please:" );
name = input.nextLine();
System.out.println( name );
System.out.println("Enter your Address please");
address = input.nextLine();
System.out.println( address );
System.out.println("Enter your Credit Card number please:");
ccnum = input.nextLine();
System.out.println( ccnum );
System.out.println("Enter your dob:");
dob = input.nextLine();
System.out.println( dob );
System.out.println("Enter your email address:");
email = input.nextLine();
System.out.println( email );
System.out.println("Re-enter your email address:");
email2 = input.nextLine();
System.out.println( email2 );
if( email == email2)
System.out.println("Enter first grocery item:");
amount1();
grocery1 = input.nextLine();
System.out.println(firstgrocery);
System.out.println("Enter second grocery item:");
amount2();
grocery2 = input.nextLine();
System.out.println(secondgrocery);
System.out.println("Enter third grocery item:");
amount3();
grocery3 = input.nextLine();
System.out.println(thirdgrocery);
System.out.println("Total cost");
}
}