I am trying t learn Java and trying to do small program but i have a little problem with this one cause i am stuck in the do while loop when i choose the answer "N" can you please help me out
package calculatrice;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Calculatrice fonction =new Calculatrice();
Scanner sr = new Scanner(System.in);
boolean noury= true;
boolean Sonia= true;
String expression = sr.nextLine();
while(noury)
{
if(expression.contains("+"))
{
float x = Float.parseFloat(expression.split("\+")[0]);
float y = Float.parseFloat(expression.split("\+")[1]);
float c = fonction.somme(x, y);
System.out.println("le resultat " + c);
}
if(expression.contains("-"))
{
float x = Float.parseFloat(expression.split("\-")[0]);
float y = Float.parseFloat(expression.split("\-")[1]);
float c = fonction.soustraction(x, y);
System.out.println("le resultat " + c);
}
if(expression.contains("*"))
{
float x = Float.parseFloat(expression.split("\*")[0]);
float y = Float.parseFloat(expression.split("\*")[1]);
float c = fonction.multiplication(x, y);
System.out.println("le resultat " + c);
}
if(expression.contains("/")){
float x = Float.parseFloat(expression.split("\/")[0]);
float y = Float.parseFloat(expression.split("\/")[1]);
float c = fonction.divion(x, y);
System.out.println("le resultat " + c);
}
do{
System.out.println("voulez vous effecteur une autre operation");
System.out.println("O pour Oui ");
System.out.println("N pour Non ");
String choix = sr.nextLine();
if ((!(choix.equals("O")))&& (!(choix.equals("N"))))
{
Sonia =false;
System.out.println("La valeur saisit n'est pas Correcte veulliez choisir N ou O seulement");
}
else if(choix.equals("N"))
{
noury=false;
}
else
{
System.out.println("Entrez une nouvelle valeur à calculer");
}
}while(Sonia);
}
}
}
Aucun commentaire:
Enregistrer un commentaire