Menu Close

Get Input from User and Display [Java] Int and Float Values …FTC


Write a Java program to declare integer variables, float variable, get input from user and
Then display their values on the output

Input:  5  6.5  7

Output:  5  6.5  7
import java.io.*;
import java.util.*;
public class temp {
	public static void main(String[] args) {
		int a,c;
		float b;
		Scanner scan = new Scanner(System.in);
		System.out.println("Enter any numbers:  ");
		a = scan.nextInt();
		b = scan.nextFloat();
		c = scan.nextInt();

		System.out.println(String.format("%d\n%.2f\n%d",a,b,c));
		scan.close();
	}
}

INPUT_1:
Enter any numbers:
2  2.5  35

OUTPUT:
2
2.50
35


INPUT_2:
Enter any numbers:
55  6.89  235

OUTPUT:
55
6.89
235


INPUT_3:
Enter any numbers:
250  8.5  36

OUTPUT:
250
8.50
36


ILLUSTRATION

Executed using javac in linux terminal