1. Member Join Date
Sep 2013
Posts
1
Rep Power
0

## Two problems

Hello all,

I have two problems when trying to code. The first question, I have no idea how to do at all, and the second question I only need to know how to prompt the user to insert a letter (either C or F).

Thank you.

Question #1. Write a program that prompts the user to enter a number and prints out
the sum of all the numbers in an even positions. The number 52934 has a 4 in position
1, 3 in position 2, 9 in position 3, 2 in position 4, and 5 in position 5. So the numbers in
even positions are 3 (in the position 2) and 2 (in the position 4). Save your program in
NumberSums.java.
Here are example runs:
Enter a number: 52934
The sum of all even positions is 5
Enter a number: 1
The sum of all even positions is 0

Question #2. Write a program that prompts the user to enter outside temperature and
whether it is in Celsius or Fahrenheit. If the user enters the temperature in Celsius, then
display the temperature in Fahrenheit and if the user enters the temperature in
Fahrenheit, then display the temperature in Celsius. If the user enters an invalid entry,
print Invalid entry. Save your program in TempConversion.java.
The formulas for the conversion are as follows
Celsius to Fahrenheit: (C is the temperature in Celsius) °C x 9/5 + 32 = °F
Fahrenheit to Celsius: (F is the temperature in Fahrenheit) (°F - 32) x 5/9 = °C
Here are two example runs.
Enter the current outside temperature: 37
Celsius or Fahrenheit (C or F): C
The current temperature in Fahrenheit is: 98.6
Enter the current outside temperature: 98.6
Celsius or Fahrenheit (C or F): F
The current temperature in Celsius is: 37  Reply With Quote

2. Senior Member Join Date
Jan 2009
Location
CA, USA
Posts
271
Rep Power
12

## Re: Two problems

For getting input from the console, you may find what you're looking for by looking up how to use a Scanner with System.in in Java. I'll also provide an example below.

Java Code:
```public static void main(String args[])
{
// create a new Scanner object, which will read input from the console (aka: System.in)
final Scanner in = new Scanner(System.in);

// Scanner has some nice methods which allow you to read different
// types of input very easily. Here are a couple examples;

// Ask for and obtain an int from the console
System.out.print("Enter an integer: ");
int someInt = in.nextInt();
System.out.println();

// Ask for and obtain a double from the console
System.out.print("Enter a double: ");
double someDouble = in.nextDouble();
System.out.println();

// close the Scanner to free up its resources
in.close();
}```  Reply With Quote

3. ## Re: Two problems

I recommend browsing the javadoc for the standard API to get an idea of what's in there. Then even if you don't remember the exact method names, you know what's in there and you can look it up.

Here are a couple methods to get you started on the first question:

String (Java Platform SE 6)
Integer (Java Platform SE 6)  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•