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

Import Public Class Public Static Void Int New: "Enter First Integer: "

The document contains 5 code snippets that demonstrate different ways to take user input in Java programs. The snippets show how to use Scanner, BufferedReader, JOptionPane, and Console classes to read input from the command line or user and then output the input values or strings.

Uploaded by

Dragu Stelian
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Import Public Class Public Static Void Int New: "Enter First Integer: "

The document contains 5 code snippets that demonstrate different ways to take user input in Java programs. The snippets show how to use Scanner, BufferedReader, JOptionPane, and Console classes to read input from the command line or user and then output the input values or strings.

Uploaded by

Dragu Stelian
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.util.

Scanner;
public class AddNumbers
{
public static void main(String args[])
{
int x, y, z;
System.out.println("Enter first integer: ");
Scanner in = new Scanner(System.in);
x = in.nextInt();
System.out.println("Enter second integer: ");
y = in.nextInt();
z = x + y;
System.out.println("Sum of entered integers is " + z);
}
}

import java.io.*;
public class AddNumbers
{
public static void main(String args[])throws Exception
{
int a, b, c;
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter first integer: ");
a = Integer.parseInt(br.readLine());
System.out.println("Enter second integer: ");
b = Integer.parseInt(br.readLine());
c = a + b;
System.out.println("Sum of entered integers is " + c);
}
}

import java.io.*;
public class AddNumbers{
public static void main(String[] args) throws IOException
{
BufferedReader is = new BufferedReader(new
InputStreamReader(System.in));
System.out.print("Please enter any input: ");
String s = is.readLine();
System.out.format("you entered: %s",s);
}
}

import javax.swing.JOptionPane;
public class AddNumbers
{
public static void main(String args[])throws Exception
{
String userInput = JOptionPane.showInputDialog("Enter your name: ");
System.out.println(userInput);
}
}

import java.io.Console;
class AddNumbers {
public static void main(String[] args)
{
Console c = System.console();
String s = c.readLine("Enter a string: ");
System.out.println("the string you entered is: " + s);
}
}

You might also like