dimanche 21 juin 2020

Repeating request if the answer is wrong #Java [duplicate]

Recently I've started learning basics of Java.

I wanted to make a code that shows that Porsche are the best cars. However, I have no idea how to make the "Sorry, that's incorrect, try again :)!" repeat if the answer is not Porsche. If you could please give me some tips I'd be very grateful.

Thanks in Advance ;)

Here is how the code looks like atm:

package com.company;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
// Showing that Porsche cars are the best

    String name;

    Scanner sc = new Scanner(System.in);
    System.out.println("Write the name of best car brand: ");
    name = sc.nextLine();
    if (name.contains("Porsche")){
        System.out.println("You're right, these are the best!");}
    else System.out.println("Sorry, that's incorrect, try again :)!");

    }
}

Aucun commentaire:

Enregistrer un commentaire