battle programmers alliance
Would you like to react to this message? Create an account in a few clicks or log in to continue.

battle programmers allianceLog in

the LivinGrimoire Artificial General Intelligence software design pattern forum

descriptionget user input in various programming languages Emptyget user input in various programming languages

more_horiz
java:

Code:

Scanner scanner = new Scanner(System.in);
System.out.println("enter input");
String str1 = scanner.nextLine();
System.out.println("input was: " + str1);


kotlin:

Code:

Scanner scanner_variable = Scanner(System.`in`)
println("enter input")
var s1:String = scanner_variable.nextLine()
println(s1)


python:

Code:

word = input("enter word\n")
print(word)


swift:

Code:

print("Enter your favorite programming language:")
var name = readLine()

print("Your favorite programming language is \(name!).")


Arduino C++

read serial from PC on Arduino

Code:

(input on serial monitor window on PC)

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  if (Serial.available() > 0) {
    int msg = Serial.parseInt();
    Serial.println(msg);
  }
}
[/code]

descriptionget user input in various programming languages Emptypython infinite input loop

more_horiz

Code:

    word: str = ""
    while not (word == "exit"):
        word = input("enter word\n")
        b1.doIt(word, "", "")

descriptionget user input in various programming languages EmptyJava infinite input loop

more_horiz
Java infinite input loop

Code:

Scanner scanner = new Scanner(System.in);
System.out.println("enter input");
String str1 = scanner.nextLine();
while (!str1.equals("exit")){
    b1.doIt(str1,"","");
    str1 = scanner.nextLine();
}

descriptionget user input in various programming languages EmptyRe: get user input in various programming languages

more_horiz
vb.net input loop:

Code:

Imports System

Module MainModule
    Sub Main()
        Dim userInput As String = ""

        ' Input loop
        While userInput.ToLower() <> "exit"
            Console.Write("Enter a value (or 'exit' to quit): ")
            userInput = Console.ReadLine()

            ' Process the user input (you can replace this with your logic)
            If userInput.ToLower() <> "exit" Then
                Console.WriteLine($"You entered: {userInput}")
            End If
        End While

        Console.WriteLine("Exiting the program. Have a great day!")
    End Sub
End Module


C# input loop

Code:

using System;

namespace InputLoopExample
{
    class Program
    {
        static void Main(string[] args)
        {
            string userInput = "";

            // Input loop
            while (userInput.ToLower() != "exit")
            {
                Console.Write("Enter a value (or 'exit' to quit): ");
                userInput = Console.ReadLine();

                // Process the user input (you can replace this with your logic)
                if (userInput.ToLower() != "exit")
                {
                    Console.WriteLine($"You entered: {userInput}");
                }
            }

            Console.WriteLine("Exiting the program. Have a great day!");
        }
    }
}
privacy_tip Permissions in this forum:
You cannot reply to topics in this forum
power_settings_newLogin to reply