0% found this document useful (0 votes)
3 views

JAVA3

The document shows a Java program that uses a Scanner to take user input of different data types including string, integer, character, float, double, long, short, byte, and boolean and then prints the values.

Uploaded by

Aditya Konnur
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

JAVA3

The document shows a Java program that uses a Scanner to take user input of different data types including string, integer, character, float, double, long, short, byte, and boolean and then prints the values.

Uploaded by

Aditya Konnur
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Program for Scanner function :

import java.util.Scanner;

public class scan

public static void main(String args[])

Scanner sc = new Scanner(System.in);

System.out.println("Enter string: ");

String str = sc.nextLine();

System.out.println("Enter Integer: ");

int i = sc.nextInt();

System.out.println("Enter Character: ");

char chr = sc.next().charAt(0);

System.out.println("Enter Float: ");

float flt = sc.nextFloat();

System.out.println("Enter Double: ");

double dbl = sc.nextDouble();

System.out.println("Enter Long: ");

long lng = sc.nextLong();

System.out.println("Enter Short: ");

short shr = sc.nextShort();

System.out.println("Enter Byte: ");

byte byt = sc.nextByte();

System.out.println("Enter Boolean: ");

boolean bool = sc.nextBoolean();

System.out.println("\n");

System.out.println("******************************************");

System.out.println("\n");

System.out.println("String is: "+ str);

System.out.println("Integer is: "+ i);


System.out.println("Character is: "+ chr);

System.out.println("Float is: "+ flt);

System.out.println("Double is: "+ dbl);

System.out.println("Long is: "+ lng);

System.out.println("Short is: "+ shr);

System.out.println("Byte is: "+ byt);

System.out.println("Boolean is: "+ bool);

Output :

You might also like