Input in Java with JOptionPane or Scanner examples of code
Exercise with swing class and JOptionPane class
package javaapplication1;
import javax.swing.*;
public class JavaApplication1 {
public static void main(String[] args) {
int a1,a2;
a1=0;a2=0;
int i=0;
int iterate;
String tmp=โโ;
tmp=JOptionPane.showInputDialog(โenter how many iterations you want to doโ);
iterate=Integer.parseInt(tmp);
while (i<=iterate)
{
System.out.println(a1+ โ โ+ a2);
i++;
a1=a1+2;
a2=a2+3;
}
}
}
esercise with input with scanner
public static void main(String[] args) {
// TODO code application logic here
int i1 = 0;
int i2 = 0;
Scanner x = new Scanner(System.in);
System.out.println(โEnter an input: โ);
i1 = x.nextInt();
System.out.println(โEnter another input: โ);
i2 = x.nextInt();
int sum = i1 + i2;
System.out.println(โThe sum of the two numbers is: โ + sum);
}
Studio Assistito con l'Intelligenza Artificiale
Vuoi padroneggiare al meglio i concetti di questo articolo? Avvia lo studio assistito per generare riassunti automatici, mappe concettuali o farti interrogare con il metodo socratico.