Skip to content

Instantly share code, notes, and snippets.

@wingyplus
Created July 5, 2011 11:03
Show Gist options
  • Save wingyplus/1064657 to your computer and use it in GitHub Desktop.
Save wingyplus/1064657 to your computer and use it in GitHub Desktop.
lab test for Nong Ying
public class test {
public static void main(String args[]) {
int x = 1;
while(x != 0) {
x = Integer.valueOf(System.console().readLine("enter number: "));
switch (x) {
case 1: oddnum();
break;
case 2: evennum();
break;
case 3: print();
break;
}
}
}
private static void oddnum() {
int x = Integer.valueOf(System.console().readLine("enter x: "));
int y = Integer.valueOf(System.console().readLine("enter y: "));
int z = Integer.valueOf(System.console().readLine("enter z: "));
for (int i = x; i <= y; i++) {
if (i % z == 0 && i % 2 == 1) {
System.out.print(i + " ");
}
}
System.out.println();
}
private static void evennum() {
}
private static void print() {
int x = Integer.valueOf(System.console().readLine("enter number x: "));
String seq = "AZYXWVUTSRQPONMLKJIHGFEDCB";
if(x != 0) {
seq = seq.substring(x) + seq.substring(0, x);
}
System.out.println(seq);
}
}
@wingyplus
Copy link
Author

substring(x) มันคือตีดตั้งแต่ index x ถึงตัวสุดท้าย

substring(0, x) คือให้มันตัดตั้งแต่ตัวแรกถึง x - 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment