2016a
(Различия между версиями)
Antonk (обсуждение | вклад) (→Ввод с клавиатуры) |
Antonk (обсуждение | вклад) |
||
| Строка 1: | Строка 1: | ||
| + | == Ввод двух чисел в строку == | ||
| + | |||
| + | <pre> | ||
| + | Scanner sc=new Scanner(System.in); | ||
| + | int num1=sc.nextInt(); | ||
| + | int num2=sc.nextInt(); | ||
| + | </re> | ||
| + | |||
== Ввод с клавиатуры == | == Ввод с клавиатуры == | ||
Версия 10:46, 15 января 2013
Ввод двух чисел в строку
Scanner sc=new Scanner(System.in);
int num1=sc.nextInt();
int num2=sc.nextInt();
</re>
== Ввод с клавиатуры ==
<pre>
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
int a, b;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
a = Integer.parseInt(br.readLine());
b = Integer.parseInt(br.readLine());
System.out.println(a+b);
}
}
Функции
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
int a, b, c;
double d;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
a = Integer.parseInt(br.readLine());
b = Integer.parseInt(br.readLine());
c = sum(a, b);
d = mySqrt(b);
System.out.println(c);
System.out.println(d);
}
public static double mySqrt(int a) {
return Math.sqrt(a);
}
public static int sum(int a, int b) {
System.out.println("I really want to sleep");
return a+b;
}
public static int max2(int a, int b) {
if (a > b) {
return a;
} else {
return b;
}
}
}