mardi 28 juillet 2020

Java shows previous if clauses input again

Hey so this is my Main class:

package com.company;

import java.util.*;
import java.lang.String;

public class Main {

public static int menu = 0;

public static void main(String[] args) {
// write your code here
    //boolean listeda= false

    System.out.println("Geben Sie ihre gewünschte Maximalmenge an Stylisten und Klienten an. (1.Stylist; 2.Client)");
    Scanner in1 = new Scanner(System.in);
    int z1 = in1.nextInt();
    int z2 = in1.nextInt();
    PersonData db = new PersonData(z1, z2);
    System.out.println("Ihre Datensätze können bis zu "+z1+" Stylisten und "+z2+" Klienten enthalten.");
    System.out.println();

    System.out.println("Geben Sie ihre gewünschte Maximalmenge Terminen. (abhängig von ihren Speicherkapazitäten)");
    Scanner in2 = new Scanner(System.in);
    int z3 = in2.nextInt();
    AppointmentData adb = new AppointmentData(z3);
    System.out.println("Ihre Datensätze können bis zu "+z3+" Einträge enthalten.");
    System.out.println();

    int menu = Menu();
    while(menu != 99) {

        if(menu == 0) Menu();
        
        else if (menu == 1) {
            System.out.println("1");
            System.out.println();
        }

        else if (menu == 2) {
            //printMap(list); //Apointment get all Entries
            System.out.println("2");
            System.out.println();
            Menu();
        }
        else if (menu == 3){
            System.out.println("Geben Sie ihre gewünschte Maximalmenge Terminen. (abhängig von ihren Speicherkapazitäten)");
            Scanner in = new Scanner(System.in);
            //int a = in.nextInt();
            db.insertStylist("Chanti", "Mueller", "c.mueller@mail.de", 123123, "cut", "wash");
            System.out.println("Ihre Datensätze können bis zu "+in.nextInt()+" Einträge enthalten.");
            System.out.println();
        }
        else if (menu == 4){

        }
        else if (menu == 5){
            System.out.println("Geben Sie ihren gewünschten Termin an. (day, month, year, hour, min, service(s))");
            Scanner in = new Scanner(System.in);
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            int d = in.nextInt();
            int e = in.nextInt();
        }
        else if (menu == 6){
        }
        
        Menu();

    }
    System.exit(0);
}


public static int Menu(){ //Menü mit Auswahlmöglichkeiten
    
    System.out.println("menu="+menu);
    
    System.out.println();
    System.out.println("Terminplaner (Zahl eintragen)");
    System.out.println();
    System.out.println("[1] Neuen Termin anlegen");
    System.out.println("[2] Termine anzeigen lassen");
    System.out.println("[3] Stylist eintragen und anzeigen lassen");
    System.out.println("[4] Client eintragen und anzeigen lassen");
    System.out.println("[5] Termin eintragen und anzeigen lassen");
    System.out.println("[99] Programm beenden");

    Scanner in = new Scanner(System.in);

    switch(in.nextInt()) {
        case 1:
            System.out.println("Neuer Termin:");
            menu = 1;
            return menu;
        case 2:
            System.out.println("Termine");
            menu = 2;
            return menu;
        case 3:
            System.out.println("Datenliste für Stylisten und Klienten serialisieren.");
            menu = 3;
            return menu;
        case 4:
            System.out.println("Datenliste für Termine serialisieren.");
            menu = 4;
            return menu;
        case 5:
            System.out.println("Datenliste für Termine serialisieren.");
            menu = 5;
            return menu;
        case 99:
            System.out.println("Planer wird geschlossen");
            System.exit(0);
            menu = 99;
            return menu;
        default:
            System.err.println("Falsche Eingabe");
            Menu();
            return menu;
    }

}

}

And if I enter 1 for example the program enters the right way, but if I put 3 afterwards the program does only the text for option 3 and then prints option 1 again. How do I fix this?

I know that I need to enter the while loop again before the if statements but somehow my code seems to go back into the previous if clauses that were already triggered.

How to stop the eternal repetition of else? The else function repeats forever in a while (true) loop. Java

I want to make a test code - Confirmation that you are not a robot. I declare a String variable named addauthentication. Next, I add the if else function. The system will ask you to write the shortest word in your language (in my case, in Armenian). If addauthentication.equals(// that shortest word) - print (you are logged into your account!).

Else ("Please write the word").

The if else function using a while loop will repeat as long as the condition is true.

Suppose my answer was not correct, then the program should display this to me: (Please write a word). But the same phrase runs forever. But, if my first answer were correct, the system would show me this (you are logged into your account!) - and yes, there were no problems with this thought. How can I correct my code so that after an incorrect answer, I could enter the correct one, and the phrase (Please write a word) is not repeated?

My code is very light, it seemed there shouldn't have been any errors. And in particular, I cannot find the answers to my question in StackOverFlow, so I was forced to ask you my question.

import java.util.Scanner;


public class RobotTest2{


public static void main(String []args){
    

String addauthentication;
        
Scanner obj = new Scanner(System.in);

       
System.out.println("Confirm with action, that you are not a robot. Write the shortest word in your language.");
addauthentication = obj.next();

while (true) {
    
    if (addauthentication.equals("և")) {
        

System.out.println("You are logged into your account!");




} else  

System.out.println("Please, write a word.");
}
}   
}

My expected result:

> Confirm with action, that you are not a robot. Write the shortest word in your language.
> 
> // user input "և"
> 
> You are logged into your account!

//other way

> Confirm with action, that you are not a robot. Write the shortest word in your language.
> 
> // user input //wrong answer
> 
> Please write a word. 
//user input ("right answer")
"You are logged into you account!"

The real result:

> Confirm with action, that you are not a robot. Write the shortest word in your language.
> 
> // user input "և"
> 
> You are logged into your account!

//Other way

>  Confirm with action, that you are not a robot. Write the shortest word in your language.

         //user input 
        //wrong answer 
        
        "Please write a word." 
    "Please write a word." 
    "Please write a word." 
    "Please write a word." 
    "Please write a word." 
    "Please write a word." 
    ......

//And so, the same phrase repeats forever.

Can't figure out why i'm Getting a 424 error when i use an IF/Then in Excel VBA

Part of a larger code, but I'm trying to fill out the blank spaces in a column that I can then delete later.

But if the column doesn't have blank spaces I need it to stop and move onto the next step instead.

I did this by having the code check column A, if Column A is blank than that means there are no blank cells in the column i'm checking.

However, whenever I ask this to do an If/Then statement to check if a particular nearby cell is blank it gives me a 424 error.

No idea what's causing this.

Range("D1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select

If ActiveCell.Offset(0, -3) Is Blank Then
GoTo Continue1
Else
End If

ActiveCell.FormulaR1C1 = "DELETEGREENELEPHANTS"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.Offset(0, -3).Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, 3).Range("A1").Select
Range(Selection, Selection.End(xlUp)).Select
Selection.FillDown

Continue1:

Checking if two three digit numbers have any of there digits that are the same in Java

I'm trying to write a program in Java that checks if at least one digit of one of the numbers, matches one digit of the other number. For example, if the two numbers are 238 and 345 it should return a certain string.
So far this is what I have, but it only works properly for the right most digit:

if ((computerGuess/10) == (userGuess/10) || (computerGuess%10) == (userGuess%10) || (computerGuess%10) == (userGuess/10) || (userGuess%10) == (computerGuess/10)) {
                System.out.println("You have won S1000");
                break;
            }

PowerShell: How to use remove-item to delete files in batches?

I have a small script which deletes files from a directory where date1 is less than date2. My script is working, however, as this is run on a directory with many files, I'd like the remove item to only remove 100 files at a time, so that I can monitor the progress with each run. Is this possible?

 if ($date1 -lt $date2) 
                { 
                    $_ | Remove-Item;
               }

Referencing data

I have a sheet that has two columns, name and date. It is pulled from another workbook that pulls data from a Google Form. I import that data on a sheet called 'Data'The next 5 sheets in that workbook are formatted as a calendar months. When the date in the Data sheet equals say August 3rd, I want the name associated with that date (same row) to show up in the calendar cell for that day. How do I do the formula for this? I know its an =IF formula but all the references are confusing me. Yes, I know I'm a novice but this is what happens when a fireman tries to use technology.... Thank you in advance.

How can I add a price range and make my num1 depend on price range in my Code?

How can I add a price range in my code and make " num1 " depended on the price range ! I want to assign some specific values to price range and then make my num1 to fetch that value ! Eg 1.if price range is (1 to 1000) then num1 = 10 ... 2.if price range is (1000 to 2000) then num1 = 20 ...

My Code :

        int num1 = Convert.ToInt32(Price.Text);
        int num2 = Convert.ToInt32(DropDownList1.SelectedValue);
        int num3 = Convert.ToInt32(DropDownList2.SelectedValue);
        int tax;
       
        int petrol;
        int cng;
        int diesel;
        int personal;
        int commercial;

        petrol = 1000;
        cng = 2000;
        diesel = 3000;
        personal = 500;
        commercial = 700;
        tax = 0;

        if (DropDownList1.SelectedValue == "1" | DropDownList2.SelectedValue == "1" )
        {
                tax = num1 + petrol + personal;
        }
        else if (DropDownList1.SelectedValue == "2" | DropDownList2.SelectedValue == "1" )
        {
                tax = num1 + cng + personal;
        }
        else if (DropDownList1.SelectedValue == "3" | DropDownList2.SelectedValue == "1" )
        {
                tax = num1 + diesel + personal;
        }
        else
        {

        }
            
        if (DropDownList1.SelectedValue == "1" | DropDownList2.SelectedValue == "2" )
        {
                tax = num1 + petrol + commercial;
        }
        else if (DropDownList1.SelectedValue == "2" | DropDownList2.SelectedValue == "2" )
        {
                tax = num1 + cng + commercial;
        }
        else if (DropDownList1.SelectedValue == "3" | DropDownList2.SelectedValue == "2" )
        {
                tax = num1 + diesel + commercial;
        }
        else
        {

        }

        CalTax.Text = tax.ToString();