Last active
December 13, 2017 12:12
-
-
Save mknorth/3f6e081ad66ff3a683f5cdbc28bed6ef to your computer and use it in GitHub Desktop.
homework2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package homework2; | |
public class IntCharFloatCharFloatCharInt { | |
public static void main(String[] args) { | |
char xChar; | |
Integer x2 = new Integer(75); | |
xChar = (char) x2.intValue(); | |
System.out.println("Char-x2: " + xChar); | |
char xCharx; | |
Float x4 = new Float(1.2f); | |
xCharx = (char) x4.floatValue(); | |
System.out.println("Float-x4: " + xCharx); | |
int intFCI; | |
char charF; | |
Float fl = new Float(1.0f); | |
System.out.println("Float-fl: " + fl); | |
charF = (char) fl.floatValue(); | |
System.out.println("Char-charF: "+ charF); | |
Character chard = new Character(charF); | |
intFCI = chard.charValue(); | |
System.out.println("Int-intFCI: " + intFCI); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package homework2; | |
import java.util.Scanner; | |
public class ScanCharVInt { | |
public static void main(String[] args) { | |
Scanner sc = new Scanner(System.in); | |
System.out.println("Enter Character symbol: "); | |
String s = sc.next(); | |
// char[] charArray = s.toCharArray(); | |
// System.out.println(charArray[0]); | |
// int k = (int) charArray[0]; | |
// System.out.println("k: " + k); | |
if (s.length() == 1) { | |
char z = s.charAt(0); | |
System.out.println("CharSymbol: " + z); | |
System.out.println("Integer: " + (int)z); | |
} else { | |
System.out.println(s); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package homework2; | |
//import java.text.CharacterIterator; | |
import java.util.Scanner; | |
public class Zadacha1DZ { | |
public static void main(String[] args) { | |
// нужно было поделить 2 числа и узнать остаток и норм число что делится без остатка | |
Scanner sc = new Scanner(System.in); | |
Scanner sd = new Scanner(System.in); | |
System.out.println("Введите первое число: "); | |
String sic = sc.next(); | |
System.out.println("Введите второе число: "); | |
String sid = sd.next(); | |
// int a = 21; | |
// int b = 8; | |
int d; | |
int k; | |
int z; | |
int a = Integer.parseInt(sic); | |
int b = Integer.parseInt(sid); | |
d = a % b; | |
k = a - d; | |
z = k / b; | |
System.out.println("И так " + a + " / " + b + " = " + z + " (и остаток " + d + ")"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package homework2; | |
public class Zadacha2DZ { | |
public static void main(String[] args) { | |
//условие: посчитать сумму цыфр двузначного числа | |
int a = 25; | |
int b,c,d; | |
b = a % 10; | |
c = (a - b)/10; | |
d = b + c; | |
System.out.println(d); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package homework2; | |
public class Zadacha3DZ { | |
/*округлить до ближайшего целого числа*/ | |
public static void main(String[] args) { | |
double a = 2.54; | |
int b; | |
b = (int) Math.round(a); | |
System.out.println(b); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package homework2; | |
public class Zadacha4DZ { | |
public static void main(String[] args) { | |
//условие: посчитать сумму цифр трехзначного числа | |
int a = 124; | |
int b,c,d,e,g; | |
b = a % 100; | |
e = (a-b)/100; | |
c = b % 10; | |
d = (b - c)/10; | |
g = e + d + c; | |
System.out.println(g); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment