Simple yes/no function...
I'm new to Java, I'm writing a simple application to convert celcius into farenheit just to teach myself some things.
So far I've written this (to generally get some information from the user):
Code Java:
import java.util.Scanner;
import java.lang.Object;
import java.lang.Boolean;
public class Code
{
public static void main(String args[])
{
//Declarations
Scanner scan = new Scanner(System.in);
String string1, string2, yes, no;
double num1;
double num2;
//First prompts
System.out.println("Enter name:");
string1 = scan.nextLine();
System.out.println("Enter surname:");
string2 = scan.nextLine();
//Yes/no function
System.out.println("Name: " + string1 + " " + string2 + "," + " is this correct?");
System.out.println("Y/N?");
}
}
In the yes/no function part I want to write a code which does the following: when the user presses 'Y', the code continues, when the user presses 'N' the code goes back to the first line.
After this I'll write the rest of the code which converts celcius into farenheight, this I can do.
Re: Simple yes/no function...
In future, please use highlight tags around your code (see my signature)
Is there a question here?
I suggest you read:
The if-then and if-then-else Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)