Scanner . , . .
importjava.util.Scanner; // Scanner java.util
public class Main {
public static void main(String[] args) {
}
}
Scanner, , . () Java System.in. () System.out. System.err
importjava.util.Scanner; //
public class Main {
public static void main(String[] args) {
Scannersc = newScanner(System.in); // sc Scanner ( System.in)
System.out.println(" "); //
inti = 0; // i int 0
i = sc.nextInt(); //
System.out.println(i); // i .
}
}
nextLine(), , .. , , , String. , , ,
importjava.util.Scanner; //
public class Main {
public static void main(String[]args) {
Scanner sc = new Scanner(System.in); // sc Scanner
Strings1,s2; // s1 s2 String
System.out.println(" "); //
s1 = sc.nextLine(); // nextLine() s1
System.out.println(" "); //
s2 = sc.nextLine(); // nextLine() s2
System.out.println(s1 + s2); //
}
}
hasNext(), - .
String , ( , ):
intlength() ( );
booleanisEmpty() , ;
Stringreplace(a, b) , a b;
StringtoLowerCase() , ; (, JAVA, java)
|
|
StringtoUpperCase() , ; (, java, JAVA)
booleanequals(s) (1), , s ( == , );
intindexOf(ch) ch ( , ). , -1. , .
intlastIndexOf(ch) , , .
intindexOf(ch,n) ch , n ( , ).
charcharAt(n) , n ( , ).
public class Main {
public static void main(String[] args) {
Strings1 = "firefox"; // , firefox
System.out.println(s1.toUpperCase()); // toUpperCase; FIREFOX
Strings2 = s1.replace('o', 'a'); // s1 s2.
System.out.println(s2); // firefax
System.out.println(s2.charAt(0)); // 0 s2, f
inti;
i = s1.length();
System.out.println(i); // 7 ( s1)
i = s1.indexOf('f');
System.out.println(i); // 0, f s1
i = s1.indexOf('r');
System.out.println(i); // 2, r s1
i = s1.lastIndexOf('f');
System.out.println(i); // 4, fs1
i = s1.indexOf('t');
System.out.println(i); // -1 .. .. s1 t
i = s1.indexOf('r',3);
System.out.println(i); // -1 .. .. e s1, e r.
}
}
, , :
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println(" ");
String s = sc.nextLine();
for (inti=0; i<s.length(); i++) {
if (s.charAt(i) == ' ')
{
System.out.println(i);
}
}
}
}
Java
, , . . ( ), ( ). (public), (private). , . .
(public, private, protected), static. . , . return , . , void.
|
|
:
public static int sum(int a, int b) {
returna+b;
}
, a b. , , , .
, .
:
ints = sum(10,15);
1. for, while, dowhile.
2. for.
3. 10 .
4. , , , .
5. , ,