Problem 1: write a randomly generated code specifies an integer number of
public class suiji {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int b;
long a=123;
long c=321;
long m=456;
System.out.println ( "Please enter your desired n:");
b=sc.nextInt();
for(int i=0;i<b;i++)
System.out.println(rand(i, a, c, m));
}
public static long rand(long r,long a,long c,long m)
{
r = ( r * a + c ) % m;
return r;
}}
The following code so special:
Different types of parameters, different types of functions, different parameters.
Determining whether a palindrome
import java.util.Scanner;
{class Huiwen public
public static void main (String args []) {
Scanner Scanner new new SC = (the System.in);
String = sc.nextLine STR (); // enter a string
if (isPalindrome (str, 0) ) {
System.out.println ( "string" + str + "palindromic sequence");
}
{the else
System.out.println ( "string" + str + "is not palindromic sequence");
}
}
public static boolean isPalindrome(String str,int index){
System.out.println(str.charAt(0) + " " + str.charAt(str.length() - 1));
if(str.charAt(0) == str.charAt(str.length() - 1)){
if(str.length() > 2)
{
return isPalindrome(str.substring(index+1,str.length()-1),0);
}else return true;
}else return false;
}
}
} |