Deprecated: Creation of dynamic property Kirki_Toolkit::$modules is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/kirki.php on line 67

Deprecated: Creation of dynamic property Kirki_Field_Switch::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Textarea::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Switch::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Checkbox::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Toggle::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Radio::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Checkbox::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Custom::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Custom::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Switch::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Radio_Image::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Radio::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Multicheck::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Switch::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Number::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Checkbox::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Switch::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Text::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Radio_Image::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Multicheck::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Switch::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Checkbox::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Checkbox::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Switch::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Switch::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Switch::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Switch::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Radio_Image::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Custom::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Custom::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Warning: Cannot modify header information - headers already sent by (output started at /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php:291) in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-includes/feed-rss2.php on line 8
Reading input from Keyboard in Java Archives - OctopusCodes https://octopuscodes.com/tag/reading-input-from-keyboard-in-java/ Sat, 21 Jan 2023 09:51:55 +0000 en-US hourly 1 https://wordpress.org/?v=6.9 https://octopuscodes.com/wp-content/uploads/2022/12/cropped-logo-80x80-1-32x32.png Reading input from Keyboard in Java Archives - OctopusCodes https://octopuscodes.com/tag/reading-input-from-keyboard-in-java/ 32 32 Assign Keyboard Input to Variables in Java https://octopuscodes.com/java/java-tutorial/basic-java/assign-keyboard-input-to-variables-in-java/ Tue, 27 Dec 2022 06:56:58 +0000 https://octopuscodes.com/?p=635 In this article, we discuss how to read data from the keyboard in Java. Read String Value from Keyboard You can use nextLine method to input an string value from the …

The post Assign Keyboard Input to Variables in Java appeared first on OctopusCodes.

]]>
In this article, we discuss how to read data from the keyboard in Java.

Read String Value from Keyboard

You can use nextLine method to input an string value from the user and assign it to the variable.

package octopuscodes.com.demo;

import java.util.Scanner;

public class Demo {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		String username;
		System.out.print("username: ");
		username = scanner.nextLine();
		System.out.println("username from keyboard: " + username);
	}
}
username: acc1
username from keyboard: acc1	
   

Read Int Value from Keyboard

You can use nextInt method to input an integer value from the user and assign it to the variable.

package octopuscodes.com.demo;

import java.util.Scanner;

public class Demo {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		System.out.print("id: ");
		int id = scanner.nextInt();
		System.out.println("id from keyboard: " + id);
	}
}
id: 123
id from keyboard: 123	
 

Read Float Value from Keyboard

You can use nextFloat method to input an float value from the user and assign it to the variable.

package octopuscodes.com.demo;

import java.util.Scanner;

public class Demo {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		float tempDegree;
		System.out.print("tempDegree: ");
		tempDegree = scanner.nextFloat();
		System.out.println("tempDegree from keyboard: " + tempDegree);
	}
}
tempDegree: 5.6
tempDegree from keyboard: 5.6
 

Read Double Value from Keyboard

You can use nextDouble method to input an double value from the user and assign it to the variable.

package octopuscodes.com.demo;

import java.util.Scanner;

public class Demo {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		double price;
		System.out.print("price: ");
		price = scanner.nextDouble();
		System.out.println("price from keyboard: " + price);
	}
}
price: 2567.54
price from keyboard: 2567.54	

Best Keyboards For Programming

Read Boolean Value from Keyboard

You can use nextBoolean method to input an boolean value from the user and assign it to the variable.

package octopuscodes.com.demo;

import java.util.Scanner;

public class Demo {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		boolean status;
		System.out.print("status: ");
		status = scanner.nextBoolean();
		System.out.println("status from keyboard: " + status);
	}
}
status: true
status from keyboard: true	
 

Read Char Value from Keyboard

You can use next and charAt method to input an character value from the user and assign it to the variable.

package octopuscodes.com.demo;

import java.util.Scanner;

public class Demo {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		char key;
		System.out.print("key: ");
		key = scanner.next().charAt(0);
		System.out.println("key from keyboard: " + key);
	}
}
key: H
key from keyboard: H	

The post Assign Keyboard Input to Variables in Java appeared first on OctopusCodes.

]]>